またいなむーさんが(@kzm0211) ハイパー便利なコマンドツールを教えてくれました。
それが、pecoとghqコマンドになります。
自分は今までClipyというスニペットツールを使って、各ホスト名を登録して呼び出していました。
他にもhistoryコマンドやローカルにあるリポジトリもcdで移動とか…
正直もっといい方法ないの!?
と嘆いていたらこいつらに出会ってしまったわけです(遅い!)
インフラエンジニア(SRE)は必須となるのでぜひ使ってみてくださいな!
■peco,ghq
・peco
標準入力で受け取ったテキストデータをインクリメンタルに絞り込みして、
選択した行を標準出力に出力するコマンド(ちなみにGo製/作者は@lestrrat様)
1 2 | ・install $ brew install peco |
・ghq
https://github.com/motemen/ghq
クローンしたgitリポジトリを管理するGo製のコマンドラインツール
1 2 | ・install $ brew install ghq |
■.zshrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ### history function peco-history-selection() { #BUFFER=`history | tail -r | awk '{$1="";print $0}' | peco` BUFFER=`history | tail -r | awk '{$1="";print $0}' | egrep -v "ls" | uniq -u | sed 's/^ //g' | peco` CURSOR=$#BUFFER zle reset-prompt } zle -N peco-history-selection bindkey '^H' peco-history-selection ### peco&ssh function peco-ssh () { local selected_host=$(awk ' tolower($1)=="host" { for (i=2; i<=NF; i++) { if ($i !~ "[*?]") { print $i } } } ' ~/.ssh/conf.d/*/config_* | sort | peco --query "$LBUFFER") if [ -n "$selected_host" ]; then BUFFER="ssh -A ${selected_host}" zle accept-line fi zle clear-screen } zle -N peco-ssh bindkey '^J' peco-ssh ## ghq alias repo='cd $(ghq list --full-path --exact| peco)' |
とりあえずbash,fishよりもzsherなので上記のようにコピペしましょう。
キーバインドは control + h
control + j
repo
と打つと各項目がでます。(キーバインドはお好みで)
イメージが伝わりにくいので実際にGIFで見てみましょう。
■history 「control + h」
上記のように control + h
で打ったコマンドのhistoryが出てきます。
選択してエンター押せば打てるのでこれは重宝する。
■ssh 「control + j」
これはすんごい
sshのconfigはincludeしているので ~/.ssh/conf.d/*/config_*
をすべて見ています。(maji便利)
■repo
repo
と打てば一瞬でローカルのリポジトリに移動できるとか神か!
■まとめ
とりあえずもっとpecoググってカスタマイズしまくってみよう!!
これないと生きていけないかも…
追記
alias repo='cd $(ghq list –full-path –exact| peco)'
↑こう書くのね?ghqで仕事用と趣味用でディレクトリ分けしてリポジトリ管理しやすくなりました | おそらくはそれさえも平凡な日々 https://t.co/gWoa6Oyaie
— adachin?SRE (@adachin0817) January 5, 2020
0件のコメント