Skip to content

Instantly share code, notes, and snippets.

@benwyrosdick
Created December 4, 2014 14:34
Show Gist options
  • Save benwyrosdick/30aea060273c562a2274 to your computer and use it in GitHub Desktop.
Save benwyrosdick/30aea060273c562a2274 to your computer and use it in GitHub Desktop.
Tab complete on git branch checkouts
function co {
git checkout $1
}
function _co {
local cur branches
[ -d .git ] || return 0
eval 'COMPREPLY=()'
cur=${COMP_WORDS[COMP_CWORD]}
branches=$(\git branch | grep -o -E "\w+")
if [ $COMP_CWORD -eq 1 ]; then
eval 'COMPREPLY=( $(compgen -o filenames -W "$branches" $cur) )'
fi
return 0
}
complete -F _co co
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment