LoginSignup
53
47

More than 5 years have passed since last update.

ターミナルでコマンド履歴の入力補完

Posted at

やりたいこと

  • 文字入力時に直近の履歴を表示させたい

3月-06-2018 20-30-18.gif

準備

インストール

zshとoh-my-zshを使った二種類の方法を紹介します

zsh

  • zsh-autosuggestionsをクローン (ここでは~/.zsh/zsh-autosuggestionへ)
% git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
  • ~/.zshrcに以下を記入
.zshrc
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
  • 設定を更新
% source ~/.zshrc

Oh My Zsh

  • $ZSH_CUSTOM/pluginszsh-autosuggestionsをクローン
  • $ZSH_CUSTOMはデフォルトだと ~/.oh-my-zsh/custom
% git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  • .zshrcのpluginsにzsh-autosuggestionsを追記
~/.zshrc
plugins=(
    git,
    zsh-autosuggestions
)
  • 設定を更新
% source ~/.zshrc

使い方

  • 文字を入力すると薄地でサジェストが表示される
  • C-fC-eで確定 3月-06-2018 20-30-18.gif
  • 色は以下を.zshrcへ追記しfgの値で変更できる。デフォルトは8
~/.zshrc
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=5'

参考

 

53
47
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
53
47