Created
July 31, 2014 06:38
-
-
Save takesato/593bb279230cc14f4a29 to your computer and use it in GitHub Desktop.
branchを最終更新順に並べてpecoで選択してcheckoutする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function peco-switch-branch() { | |
local branch=$( | |
( | |
for i in `git branch | colrm 1 2|grep -v detached`; | |
do | |
echo `git log --date=iso8601 -n 1 --pretty="format:[%ai] %h" $i` $i; | |
done | |
) | sort -r|peco --query "$LBUFFER" | cut -f 5 -d" ") | |
if [ -n "$branch" ]; then | |
BUFFER="git checkout ${branch}" | |
CURSOR=$#BUFFER | |
zle accept-line | |
fi | |
zle clear-screen | |
} | |
zle -N peco-switch-branch | |
bindkey '^x^b' peco-switch-branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
元ネタは http://d.hatena.ne.jp/kazuhooku/20130205/1360039870 です