7
7

More than 1 year has passed since last update.

git status から peco でファイルを絞り込んでカーソル位置にパスを挿入する zsh widget

Last updated at Posted at 2015-02-05

を書きました。

##動機

元ネタ : git addするファイルをpecoで選択できるようにした

  • これを git add だけでなく git reset, git rm, etc でも使いたい
    • しかしそのたびにキーバインドを考えるのは嫌だ
    • 覚えるのも嫌だ
      • ということはカーソル位置にファイルパスを含められれば解決だ

.zshrc


function peco_select_from_git_status(){
    git status --porcelain | \
    peco | \
    awk -F ' ' '{print $NF}' | \
    tr '\n' ' '
}

function peco_insert_selected_git_files(){
    LBUFFER+=$(peco_select_from_git_status)
    CURSOR=$#LBUFFER
    zle reset-prompt
}

zle -N peco_insert_selected_git_files
bindkey "^g^s" peco_insert_selected_git_files

これでもう git rm や git diff の直後に ^g^s と打てば peco から git status 内のファイルを絞り込めます。複数個の選択もバッチリです。

しあわせ!

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