Skip to content

Instantly share code, notes, and snippets.

@dohq
Last active July 27, 2019 10:12
Show Gist options
  • Save dohq/7cb290f0a9a90e8f24f0f4912f6633b8 to your computer and use it in GitHub Desktop.
Save dohq/7cb290f0a9a90e8f24f0f4912f6633b8 to your computer and use it in GitHub Desktop.
fzf-branch
function fzf-branch() {
local selected_branch=$(git for-each-ref --format='%(refname)' --sort=-committerdate refs/heads | perl -pne 's{^refs/heads/}{}' | fzf --query "$LBUFFER" --prompt="Git Branch > ")
if [ -n "$selected_branch" ]; then
BUFFER="git checkout ${selected_branch}"
zle accept-line
fi
zle reset-prompt
}
zle -N fzf-branch
bindkey "^b" fzf-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment