LoginSignup
2
1

More than 5 years have passed since last update.

ターミナルでコマンド履歴の絞り込み検索

Posted at

やりたいこと

  • コマンド履歴をいい感じに絞り込み検索したい

3月-06-2018 20-23-22.gif

※以下zshを使っていることを前提としています

準備

インストール

  • Homebrewでpecoをインストール
% brew install peco
  • .zshrcに以下を追記
~/.zshrc

function peco-select-history() {
    # historyを番号なし、逆順、最初から表示。
    # 順番を保持して重複を削除。
    # カーソルの左側の文字列をクエリにしてpecoを起動
    # \nを改行に変換
    BUFFER="$(\history -nr 1 | awk '!a[$0]++' | peco --query "$LBUFFER" | sed 's/\\n/\n/')"
    CURSOR=$#BUFFER             # カーソルを文末に移動
    zle -R -c                   # refresh
}
zle -N peco-select-history
bindkey '^@' peco-select-history
  • 設定を更新
% source ~/.zshrc

使い方

  • ターミナルでCtrl-@

3月-06-2018 20-23-22.gif

参考

 

2
1
0

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
2
1