Skip to content

Instantly share code, notes, and snippets.

@dameleon
Last active August 29, 2015 14:10
Show Gist options
  • Save dameleon/777180f2d52624083dc5 to your computer and use it in GitHub Desktop.
Save dameleon/777180f2d52624083dc5 to your computer and use it in GitHub Desktop.
function peco-git-branch-awesome () {
local selected_branch_name="$(git branch -a | peco | tr -d ' ')"
case "$selected_branch_name" in
*-\>* )
selected_branch_name="$(echo ${selected_branch_name} | perl -ne 's/^.*->\s(.*?)\/(.*)$/\2/;print')";;
remotes* )
selected_branch_name="$(echo ${selected_branch_name} | perl -ne 's/^.*?remotes\/(.*?)\/(.*)$/\2/;print')";;
esac
if [ -n "$selected_branch_name" ]; then
BUFFER="git checkout ${selected_branch_name}"
zle accept-line
fi
zle clear-screen
}
zle -N peco-git-branch-awesome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment