Skip to content

Instantly share code, notes, and snippets.

@chadwhitacre
Last active December 20, 2015 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadwhitacre/6141081 to your computer and use it in GitHub Desktop.
Save chadwhitacre/6141081 to your computer and use it in GitHub Desktop.
# This adds tab completion of git branch names (including remotes) to several
# git-related bash aliases I have set up:
#
# co git checkout
# gb git branch
# gm git merge
#
#
# Bugs:
#
# When I tab-complete the empty string I get a directory listing plus the
# remotes. I would prefer to just have all branches.
#
#
# References:
#
# https://raw.github.com/django/django/master/extras/django_bash_completion
# http://fahdshariff.blogspot.com/2011/04/writing-your-own-bash-completion.html
_branch_names()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "`gb` `gb -r`" -- $cur) )
}
complete -F _branch_names co
complete -F _branch_names gb
complete -F _branch_names gm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment