Skip to content

Instantly share code, notes, and snippets.

@iorionda
Created July 7, 2014 03:02
Show Gist options
  • Select an option

  • Save iorionda/ee6b19d08f0fc162a647 to your computer and use it in GitHub Desktop.

Select an option

Save iorionda/ee6b19d08f0fc162a647 to your computer and use it in GitHub Desktop.
################################################################################
# peco-git-branch-selector
################################################################################
function peco-git-branch-selector() {
local tac
if which tac > /dev/null; then
tac="tac"
else
tac="tail -r"
fi
git rev-parse --git-dir >/dev/null 2>&1
if [[ $? == 0 ]]; then
BUFFER=$(git branch | grep -v "*" | eval $tac | peco --query "$LBUFFER")
if [[ $? == 0 ]];then
BUFFER=$(echo $BUFFER | tr -d ' ')
BUFFER="git checkout $BUFFER"
CURSOR=$#BUFFER
fi
fi
zle clear-screen
}
zle -N peco-git-branch-selector
bindkey '^xg' peco-git-branch-selector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment