1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#
# 'git' bash completion
#
# Copyright (c) Paolo Giarrusso, 2005
# Copyright (c) Ben Clifford, 2005
#
bashdefault="-o bashdefault"
default="-o default"
o_help="-h"
_git ()
{
local cur cmd cmds
cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
if [ $COMP_CWORD -eq 1 ]; then
cmds="$(git help -a | grep --regexp '^ ')"
COMPREPLY=( $(compgen -W "${cmds}" -- $cur) )
else
local cmd=${COMP_WORDS[1]}
case $cmd in
branch)
_git_branch
;;
checkout)
_git_checkout
;;
cherry)
_git_cherry
;;
diff-tree)
_git_diff_tree
;;
fetch)
_git_fetch
;;
ls-tree)
_git_ls_tree
;;
name-rev)
_git_name_rev
;;
pull)
_git_pull
;;
push)
_git_push
;;
rebase)
_git_rebase
;;
show-branch)
_git_show_branch
;;
*)
_git_default
;;
esac
fi
}
_git_branch ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
# git branch NEWBRANCHNAME BASE
# always complete on branch names
# XXX could probably just complete on the first 2 args
COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
}
_git_checkout ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=""
local opts="-f -b"
if [ $COMP_CWORD -gt 1 ]; then
prev=${COMP_WORDS[COMP_CWORD-1]}
fi
# git checkout [-f] [-b <new_branch>] [<branch>] [<paths>...]
if [ "$prev" = "-b" ]; then
# complete on branch name
COMPREPLY=( $(compgen -W "$(__git_heads)" -- $cur) )
else
COMPREPLY=( $(compgen -W "${opts} $(__git_heads)" -- $cur) )
# XXX actually here, need to detect if it is the first
# non-option parameter - if so, complete with git_refs,
# otherwise complete with filename
fi
}
_git_cherry ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
}
_git_diff_tree ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local opts="--stdin -m -c --cc -s -v --pretty -t -r --root"
#git diff-tree [--stdin] [-m] [-c] [--cc] [-s] [-v] [--pretty] [-t] [-r] [--root] [<common diff options>] <tree-ish> [<tree-ish>] [<path>...]
COMPREPLY=( $(compgen -f -W "${opts} $(__git_heads)" -- $cur) )
}
_git_fetch ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(__git_remotes)" -- $cur) )
}
_git_ls_tree ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local opts="-d -r -t -z --name-only --name-status --full-name"
#git ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] <tree-ish> [path...]
# this is missing some functionality -- we should complete the
# first non-opt as a treeish, and the rest as paths but actually
# what we do is just complete both treeish and paths for everything
COMPREPLY=( $(compgen -f -W "${opts} $(__git_heads)" -- $cur) )
}
_git_name_rev ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "--tags --all --stdin $(__git_refs)" -- $cur) )
}
_git_pull ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(__git_remotes)" -- $cur) )
}
_git_push ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(__git_remotes)" -- $cur) )
}
_git_rebase ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(__git_refs)" -- $cur) )
}
_git_show_branch ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "--all --heads --tags --topo-order --current --more= --list --independent --merge-base --no-name --sha1-name $(__git_refs)" -- $cur) )
}
_git_default ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen $default -W "${o_help}" -f -- $cur) )
}
complete $default -F _git git
complete $default -F _git_branch git-branch
complete $default -F _git_checkout git-checkout
complete $default -F _git_cherry git-cherry
complete $default -F _git_diff_tree git-diff-tree
complete $default -F _git_fetch git-fetch
complete $default -F _git_ls_tree git-ls-tree
complete $default -F _git_name_rev git-name-rev
complete $default -F _git_pull git-pull
complete $default -F _git_push git-push
complete $default -F _git_rebase git-rebase
complete $default -F _git_show_branch git-show-branch
# TODO: complete any other git-* commands using _git_default
# vim: syntax=sh sw=4 ts=4 expandtab cindent :
|