Skip to content

Instantly share code, notes, and snippets.

@takesato
Created July 31, 2014 06:38
Show Gist options
  • Save takesato/593bb279230cc14f4a29 to your computer and use it in GitHub Desktop.
Save takesato/593bb279230cc14f4a29 to your computer and use it in GitHub Desktop.
branchを最終更新順に並べてpecoで選択してcheckoutする
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
@takesato
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment