LoginSignup
28
24

More than 5 years have passed since last update.

gitのbranch選択をpecoで楽にする。

Posted at

なにが嬉しいのか?

  • gitのbranchを楽に選択できる。
  • checkout, push, pullなどが楽にできる。

git checkoutをpecoで行うpecoの関数はあったのですが、
汎用的にしたいよなーと思いましたのでbranchのみを選択するスクリプトを書きました。

ソース

.zshrc
function peco-branch () {
    local branch=$(git branch -a | peco | tr -d ' ' | tr -d '*')
    if [ -n "$branch" ]; then
      if [ -n "$LBUFFER" ]; then
        local new_left="${LBUFFER%\ } $branch"
      else
        local new_left="$branch"
      fi
      BUFFER=${new_left}${RBUFFER}
      CURSOR=${#new_left}
    fi
}
zle -N peco-branch
bindkey '^xb' peco-branch # C-x b でブランチ選択
28
24
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
28
24