Skip to content

Instantly share code, notes, and snippets.

@wmh
Created May 22, 2013 15:24
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 wmh/5628456 to your computer and use it in GitHub Desktop.
Save wmh/5628456 to your computer and use it in GitHub Desktop.
grb auto complete by ash
_grb()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local verb=${COMP_WORDS[1]}
local position=${COMP_CWORD}
if [[ "$verb" == "explain" ]]; then
let "position = $position - 1"
fi
case "$position" in
1)
COMPREPLY=( $(compgen -W "help explain create new delete destroy kill remove rm rename rn mv move track follow grab fetch" -- $cur) )
;;
2)
COMPREPLY=( $(compgen -W "$(_grb_branch)" -- $cur))
;;
3)
COMPREPLY=( $(compgen -W "$(_grb_remotes)" -- $cur))
;;
esac
}
_grb_branch()
{
{
git for-each-ref refs/remotes --format="%(refname:short)" |
sed 's/^.*\///g' |
sed 's/^HEAD$//g' ;
git for-each-ref refs/heads --format="%(refname:short)";
} | sort | uniq
}
_grb_remotes()
{
local i IFS=$'\n'
for i in $(git config --get-regexp 'remote\..*\.url' 2>/dev/null); do
i="${i#remote.}"
echo "${i/.url*/}"
done
}
complete -F _grb grb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment