Created
December 4, 2014 14:34
-
-
Save benwyrosdick/30aea060273c562a2274 to your computer and use it in GitHub Desktop.
Tab complete on git branch checkouts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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