-
Notifications
You must be signed in to change notification settings - Fork 9
/
gitext.completion.bash
189 lines (168 loc) · 3.77 KB
/
gitext.completion.bash
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
#! /usr/bin/env bash
#
# Bash completion for git-externals
#
# ============
# Installation
# ============
#
# Completion after typing "git-externals"
# ===========================
# Put: "source gitext.completion.bash" in your .bashrc
# or place it in "/etc/bash_completion.d" folder, it will
# be sourced automatically.
#
# completion after typing "git externals" (through git-completion)
# ===========================
# Put: Ensure git-completion is installed (normally it comes
# with Git on Debian systems). In case it isn't, see:
# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
_git_ext_cmds=" \
add \
diff \
foreach \
info \
freeze \
remove \
status \
update
"
_git_externals ()
{
local subcommands="$(echo $_git_ext_cmds)"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
return
fi
case "$subcommand" in
add)
__git_ext_add
return
;;
diff)
__git_ext_diff
return
;;
info)
__git_ext_info
return
;;
update|foreach)
__git_ext_update_foreach
return
;;
remove)
__git_ext_remove
return
;;
status)
__git_ext_status
return
;;
*)
COMPREPLY=()
;;
esac
}
__git_ext_info ()
{
local cur
local opts=""
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
-*) opts="--recursive --no-recursive" ;;
*) __gitext_complete_externals "${cur}" ;;
esac
if [[ -n "${opts}" ]]; then
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${opts}" -- "${cur}") )
fi
}
__git_ext_status ()
{
local cur
local opts=""
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in
-*) opts="--porcelain --verbose --no-verbose" ;;
*) __gitext_complete_externals "${cur}" ;;
esac
if [[ -n "${opts}" ]]; then
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${opts}" -- "${cur}") )
fi
}
__git_ext_diff ()
{
local cur
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
__gitext_complete_externals "${cur}"
}
__git_ext_update_foreach ()
{
local opts=""
opts="--recursive --no-recursive --gitsvn --no-gitsvn --reset"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${opts}" -- "${cur}") )
}
__git_ext_add ()
{
local opts=""
opts="--branch --tag"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${opts}" -- "${cur}") )
}
__git_externals ()
{
local cur prev
local i cmd cmd_index option option_index
local opts=""
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Search for the subcommand
local skip_next=0
for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ ${skip_next} -eq 1 ]]; then
skip_next=0;
elif [[ ${COMP_WORDS[i]} != -* ]]; then
cmd="${COMP_WORDS[i]}"
cmd_index=${i}
break
elif [[ ${COMP_WORDS[i]} == -f ]]; then
skip_next=1
fi
done
options=""
if [[ $COMP_CWORD -le $cmd_index ]]; then
# The user has not specified a subcommand yet
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${_git_ext_cmds}" -- "${cur}") )
else
case ${cmd} in
diff)
__git_ext_diff ;;
info)
__git_ext_info ;;
status)
__git_ext_status ;;
update|foreach)
__git_ext_update_foreach ;;
add)
__git_ext_update_add ;;
esac # case ${cmd}
fi # command specified
if [[ -n "${options}" ]]; then
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${options}" -- "${cur}") )
fi
}
__gitext_complete_externals ()
{
local IFS=$'\n'
local cur="${1}"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$(git-externals list 2>/dev/null)" -- "${cur}") )
}
# alias __git_find_on_cmdline for backwards compatibility
if [ -z "`type -t __git_find_on_cmdline`" ]; then
alias __git_find_on_cmdline=__git_find_subcommand
fi
complete -F __git_externals git-externals