Skip to content

Instantly share code, notes, and snippets.

@dohq
Last active September 21, 2018 15:26
Show Gist options
  • Save dohq/8a1c63c104917d3ad1ffd879854826ca to your computer and use it in GitHub Desktop.
Save dohq/8a1c63c104917d3ad1ffd879854826ca to your computer and use it in GitHub Desktop.
peco-branch
#bindkey '^B' select branch for Peco
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 '^b' peco-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment