##// END OF EJS Templates
Support branch names in contrib/bash_completion...
Steve Losh -
r8719:b5e9ed63 default
parent child Browse files
Show More
@@ -1,515 +1,532 b''
1 # bash completion for the Mercurial distributed SCM
1 # bash completion for the Mercurial distributed SCM
2
2
3 # Docs:
3 # Docs:
4 #
4 #
5 # If you source this file from your .bashrc, bash should be able to
5 # If you source this file from your .bashrc, bash should be able to
6 # complete a command line that uses hg with all the available commands
6 # complete a command line that uses hg with all the available commands
7 # and options and sometimes even arguments.
7 # and options and sometimes even arguments.
8 #
8 #
9 # Mercurial allows you to define additional commands through extensions.
9 # Mercurial allows you to define additional commands through extensions.
10 # Bash should be able to automatically figure out the name of these new
10 # Bash should be able to automatically figure out the name of these new
11 # commands and their options. See below for how to define _hg_opt_foo
11 # commands and their options. See below for how to define _hg_opt_foo
12 # and _hg_cmd_foo functions to fine-tune the completion for option and
12 # and _hg_cmd_foo functions to fine-tune the completion for option and
13 # non-option arguments, respectively.
13 # non-option arguments, respectively.
14 #
14 #
15 #
15 #
16 # Notes about completion for specific commands:
16 # Notes about completion for specific commands:
17 #
17 #
18 # - the completion function for the email command from the patchbomb
18 # - the completion function for the email command from the patchbomb
19 # extension will try to call _hg_emails to get a list of e-mail
19 # extension will try to call _hg_emails to get a list of e-mail
20 # addresses. It's up to the user to define this function. For
20 # addresses. It's up to the user to define this function. For
21 # example, put the addresses of the lists that you usually patchbomb
21 # example, put the addresses of the lists that you usually patchbomb
22 # in ~/.patchbomb-to and the addresses that you usually use to send
22 # in ~/.patchbomb-to and the addresses that you usually use to send
23 # the patchbombs in ~/.patchbomb-from and use something like this:
23 # the patchbombs in ~/.patchbomb-from and use something like this:
24 #
24 #
25 # _hg_emails()
25 # _hg_emails()
26 # {
26 # {
27 # if [ -r ~/.patchbomb-$1 ]; then
27 # if [ -r ~/.patchbomb-$1 ]; then
28 # cat ~/.patchbomb-$1
28 # cat ~/.patchbomb-$1
29 # fi
29 # fi
30 # }
30 # }
31 #
31 #
32 #
32 #
33 # Writing completion functions for additional commands:
33 # Writing completion functions for additional commands:
34 #
34 #
35 # If it exists, the function _hg_cmd_foo will be called without
35 # If it exists, the function _hg_cmd_foo will be called without
36 # arguments to generate the completion candidates for the hg command
36 # arguments to generate the completion candidates for the hg command
37 # "foo". If the command receives some arguments that aren't options
37 # "foo". If the command receives some arguments that aren't options
38 # even though they start with a "-", you can define a function called
38 # even though they start with a "-", you can define a function called
39 # _hg_opt_foo to generate the completion candidates. If _hg_opt_foo
39 # _hg_opt_foo to generate the completion candidates. If _hg_opt_foo
40 # doesn't return 0, regular completion for options is attempted.
40 # doesn't return 0, regular completion for options is attempted.
41 #
41 #
42 # In addition to the regular completion variables provided by bash,
42 # In addition to the regular completion variables provided by bash,
43 # the following variables are also set:
43 # the following variables are also set:
44 # - $hg - the hg program being used (e.g. /usr/bin/hg)
44 # - $hg - the hg program being used (e.g. /usr/bin/hg)
45 # - $cmd - the name of the hg command being completed
45 # - $cmd - the name of the hg command being completed
46 # - $cmd_index - the index of $cmd in $COMP_WORDS
46 # - $cmd_index - the index of $cmd in $COMP_WORDS
47 # - $cur - the current argument being completed
47 # - $cur - the current argument being completed
48 # - $prev - the argument before $cur
48 # - $prev - the argument before $cur
49 # - $global_args - "|"-separated list of global options that accept
49 # - $global_args - "|"-separated list of global options that accept
50 # an argument (e.g. '--cwd|-R|--repository')
50 # an argument (e.g. '--cwd|-R|--repository')
51 # - $canonical - 1 if we canonicalized $cmd before calling the function
51 # - $canonical - 1 if we canonicalized $cmd before calling the function
52 # 0 otherwise
52 # 0 otherwise
53 #
53 #
54
54
55 shopt -s extglob
55 shopt -s extglob
56
56
57 _hg_commands()
57 _hg_commands()
58 {
58 {
59 local commands
59 local commands
60 commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands=""
60 commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands=""
61 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
61 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
62 }
62 }
63
63
64 _hg_paths()
64 _hg_paths()
65 {
65 {
66 local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')"
66 local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')"
67 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
67 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
68 }
68 }
69
69
70 _hg_repos()
70 _hg_repos()
71 {
71 {
72 local i
72 local i
73 for i in $(compgen -d -- "$cur"); do
73 for i in $(compgen -d -- "$cur"); do
74 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
74 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
75 done
75 done
76 }
76 }
77
77
78 _hg_status()
78 _hg_status()
79 {
79 {
80 local files="$("$hg" status -n$1 . 2>/dev/null)"
80 local files="$("$hg" status -n$1 . 2>/dev/null)"
81 local IFS=$'\n'
81 local IFS=$'\n'
82 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
82 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
83 }
83 }
84
84
85 _hg_tags()
85 _hg_tags()
86 {
86 {
87 local tags="$("$hg" tags -q 2>/dev/null)"
87 local tags="$("$hg" tags -q 2>/dev/null)"
88 local IFS=$'\n'
88 local IFS=$'\n'
89 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
89 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
90 }
90 }
91
91
92 _hg_branches()
93 {
94 local branches="$("$hg" branches -q 2>/dev/null)"
95 local IFS=$'\n'
96 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$branches' -- "$cur"))
97 }
98
92 # this is "kind of" ugly...
99 # this is "kind of" ugly...
93 _hg_count_non_option()
100 _hg_count_non_option()
94 {
101 {
95 local i count=0
102 local i count=0
96 local filters="$1"
103 local filters="$1"
97
104
98 for ((i=1; $i<=$COMP_CWORD; i++)); do
105 for ((i=1; $i<=$COMP_CWORD; i++)); do
99 if [[ "${COMP_WORDS[i]}" != -* ]]; then
106 if [[ "${COMP_WORDS[i]}" != -* ]]; then
100 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
107 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
101 continue
108 continue
102 fi
109 fi
103 count=$(($count + 1))
110 count=$(($count + 1))
104 fi
111 fi
105 done
112 done
106
113
107 echo $(($count - 1))
114 echo $(($count - 1))
108 }
115 }
109
116
110 _hg()
117 _hg()
111 {
118 {
112 local cur prev cmd cmd_index opts i
119 local cur prev cmd cmd_index opts i
113 # global options that receive an argument
120 # global options that receive an argument
114 local global_args='--cwd|-R|--repository'
121 local global_args='--cwd|-R|--repository'
115 local hg="$1"
122 local hg="$1"
116 local canonical=0
123 local canonical=0
117
124
118 COMPREPLY=()
125 COMPREPLY=()
119 cur="$2"
126 cur="$2"
120 prev="$3"
127 prev="$3"
121
128
122 # searching for the command
129 # searching for the command
123 # (first non-option argument that doesn't follow a global option that
130 # (first non-option argument that doesn't follow a global option that
124 # receives an argument)
131 # receives an argument)
125 for ((i=1; $i<=$COMP_CWORD; i++)); do
132 for ((i=1; $i<=$COMP_CWORD; i++)); do
126 if [[ ${COMP_WORDS[i]} != -* ]]; then
133 if [[ ${COMP_WORDS[i]} != -* ]]; then
127 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
134 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
128 cmd="${COMP_WORDS[i]}"
135 cmd="${COMP_WORDS[i]}"
129 cmd_index=$i
136 cmd_index=$i
130 break
137 break
131 fi
138 fi
132 fi
139 fi
133 done
140 done
134
141
135 if [[ "$cur" == -* ]]; then
142 if [[ "$cur" == -* ]]; then
136 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
143 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
137 return
144 return
138 fi
145 fi
139
146
140 opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null)
147 opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null)
141
148
142 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
149 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
143 return
150 return
144 fi
151 fi
145
152
146 # global options
153 # global options
147 case "$prev" in
154 case "$prev" in
148 -R|--repository)
155 -R|--repository)
149 _hg_paths
156 _hg_paths
150 _hg_repos
157 _hg_repos
151 return
158 return
152 ;;
159 ;;
153 --cwd)
160 --cwd)
154 # Stick with default bash completion
161 # Stick with default bash completion
155 return
162 return
156 ;;
163 ;;
157 esac
164 esac
158
165
159 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
166 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
160 _hg_commands
167 _hg_commands
161 return
168 return
162 fi
169 fi
163
170
164 # try to generate completion candidates for whatever command the user typed
171 # try to generate completion candidates for whatever command the user typed
165 local help
172 local help
166 if _hg_command_specific; then
173 if _hg_command_specific; then
167 return
174 return
168 fi
175 fi
169
176
170 # canonicalize the command name and try again
177 # canonicalize the command name and try again
171 help=$("$hg" help "$cmd" 2>/dev/null)
178 help=$("$hg" help "$cmd" 2>/dev/null)
172 if [ $? -ne 0 ]; then
179 if [ $? -ne 0 ]; then
173 # Probably either the command doesn't exist or it's ambiguous
180 # Probably either the command doesn't exist or it's ambiguous
174 return
181 return
175 fi
182 fi
176 cmd=${help#hg }
183 cmd=${help#hg }
177 cmd=${cmd%%[$' \n']*}
184 cmd=${cmd%%[$' \n']*}
178 canonical=1
185 canonical=1
179 _hg_command_specific
186 _hg_command_specific
180 }
187 }
181
188
182 _hg_command_specific()
189 _hg_command_specific()
183 {
190 {
184 if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
191 if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
185 "_hg_cmd_$cmd"
192 "_hg_cmd_$cmd"
186 return 0
193 return 0
187 fi
194 fi
188
195
189 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
196 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
190 if [ $canonical = 1 ]; then
197 if [ $canonical = 1 ]; then
191 _hg_tags
198 _hg_tags
199 _hg_branches
192 return 0
200 return 0
193 elif [[ status != "$cmd"* ]]; then
201 elif [[ status != "$cmd"* ]]; then
194 _hg_tags
202 _hg_tags
203 _hg_branches
195 return 0
204 return 0
196 else
205 else
197 return 1
206 return 1
198 fi
207 fi
199 fi
208 fi
200
209
201 case "$cmd" in
210 case "$cmd" in
202 help)
211 help)
203 _hg_commands
212 _hg_commands
204 ;;
213 ;;
205 export)
214 export)
206 if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
215 if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
207 return 0
216 return 0
208 fi
217 fi
209 _hg_tags
218 _hg_tags
219 _hg_branches
210 ;;
220 ;;
211 manifest|update)
221 manifest|update)
212 _hg_tags
222 _hg_tags
223 _hg_branches
213 ;;
224 ;;
214 pull|push|outgoing|incoming)
225 pull|push|outgoing|incoming)
215 _hg_paths
226 _hg_paths
216 _hg_repos
227 _hg_repos
217 ;;
228 ;;
218 paths)
229 paths)
219 _hg_paths
230 _hg_paths
220 ;;
231 ;;
221 add)
232 add)
222 _hg_status "u"
233 _hg_status "u"
223 ;;
234 ;;
224 merge)
235 merge)
225 _hg_tags
236 _hg_tags
237 _hg_branches
226 ;;
238 ;;
227 commit)
239 commit)
228 _hg_status "mar"
240 _hg_status "mar"
229 ;;
241 ;;
230 remove)
242 remove)
231 _hg_status "d"
243 _hg_status "d"
232 ;;
244 ;;
233 forget)
245 forget)
234 _hg_status "a"
246 _hg_status "a"
235 ;;
247 ;;
236 diff)
248 diff)
237 _hg_status "mar"
249 _hg_status "mar"
238 ;;
250 ;;
239 revert)
251 revert)
240 _hg_status "mard"
252 _hg_status "mard"
241 ;;
253 ;;
242 clone)
254 clone)
243 local count=$(_hg_count_non_option)
255 local count=$(_hg_count_non_option)
244 if [ $count = 1 ]; then
256 if [ $count = 1 ]; then
245 _hg_paths
257 _hg_paths
246 fi
258 fi
247 _hg_repos
259 _hg_repos
248 ;;
260 ;;
249 debugindex|debugindexdot)
261 debugindex|debugindexdot)
250 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
262 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
251 ;;
263 ;;
252 debugdata)
264 debugdata)
253 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
265 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
254 ;;
266 ;;
255 *)
267 *)
256 return 1
268 return 1
257 ;;
269 ;;
258 esac
270 esac
259
271
260 return 0
272 return 0
261 }
273 }
262
274
263 complete -o bashdefault -o default -F _hg hg 2>/dev/null \
275 complete -o bashdefault -o default -F _hg hg 2>/dev/null \
264 || complete -o default -F _hg hg
276 || complete -o default -F _hg hg
265
277
266
278
267 # Completion for commands provided by extensions
279 # Completion for commands provided by extensions
268
280
269 # mq
281 # mq
270 _hg_ext_mq_patchlist()
282 _hg_ext_mq_patchlist()
271 {
283 {
272 local patches
284 local patches
273 patches=$("$hg" $1 2>/dev/null)
285 patches=$("$hg" $1 2>/dev/null)
274 if [ $? -eq 0 ] && [ "$patches" ]; then
286 if [ $? -eq 0 ] && [ "$patches" ]; then
275 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
287 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
276 return 0
288 return 0
277 fi
289 fi
278 return 1
290 return 1
279 }
291 }
280
292
281 _hg_ext_mq_queues()
293 _hg_ext_mq_queues()
282 {
294 {
283 local root=$("$hg" root 2>/dev/null)
295 local root=$("$hg" root 2>/dev/null)
284 local n
296 local n
285 for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
297 for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
286 # I think we're usually not interested in the regular "patches" queue
298 # I think we're usually not interested in the regular "patches" queue
287 # so just filter it.
299 # so just filter it.
288 if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
300 if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
289 COMPREPLY=(${COMPREPLY[@]:-} "$n")
301 COMPREPLY=(${COMPREPLY[@]:-} "$n")
290 fi
302 fi
291 done
303 done
292 }
304 }
293
305
294 _hg_cmd_qpop()
306 _hg_cmd_qpop()
295 {
307 {
296 if [[ "$prev" = @(-n|--name) ]]; then
308 if [[ "$prev" = @(-n|--name) ]]; then
297 _hg_ext_mq_queues
309 _hg_ext_mq_queues
298 return
310 return
299 fi
311 fi
300 _hg_ext_mq_patchlist qapplied
312 _hg_ext_mq_patchlist qapplied
301 }
313 }
302
314
303 _hg_cmd_qpush()
315 _hg_cmd_qpush()
304 {
316 {
305 if [[ "$prev" = @(-n|--name) ]]; then
317 if [[ "$prev" = @(-n|--name) ]]; then
306 _hg_ext_mq_queues
318 _hg_ext_mq_queues
307 return
319 return
308 fi
320 fi
309 _hg_ext_mq_patchlist qunapplied
321 _hg_ext_mq_patchlist qunapplied
310 }
322 }
311
323
312 _hg_cmd_qgoto()
324 _hg_cmd_qgoto()
313 {
325 {
314 if [[ "$prev" = @(-n|--name) ]]; then
326 if [[ "$prev" = @(-n|--name) ]]; then
315 _hg_ext_mq_queues
327 _hg_ext_mq_queues
316 return
328 return
317 fi
329 fi
318 _hg_ext_mq_patchlist qseries
330 _hg_ext_mq_patchlist qseries
319 }
331 }
320
332
321 _hg_cmd_qdelete()
333 _hg_cmd_qdelete()
322 {
334 {
323 local qcmd=qunapplied
335 local qcmd=qunapplied
324 if [[ "$prev" = @(-r|--rev) ]]; then
336 if [[ "$prev" = @(-r|--rev) ]]; then
325 qcmd=qapplied
337 qcmd=qapplied
326 fi
338 fi
327 _hg_ext_mq_patchlist $qcmd
339 _hg_ext_mq_patchlist $qcmd
328 }
340 }
329
341
330 _hg_cmd_qsave()
342 _hg_cmd_qsave()
331 {
343 {
332 if [[ "$prev" = @(-n|--name) ]]; then
344 if [[ "$prev" = @(-n|--name) ]]; then
333 _hg_ext_mq_queues
345 _hg_ext_mq_queues
334 return
346 return
335 fi
347 fi
336 }
348 }
337
349
338 _hg_cmd_strip()
350 _hg_cmd_strip()
339 {
351 {
340 _hg_tags
352 _hg_tags
353 _hg_branches
341 }
354 }
342
355
343 _hg_cmd_qcommit()
356 _hg_cmd_qcommit()
344 {
357 {
345 local root=$("$hg" root 2>/dev/null)
358 local root=$("$hg" root 2>/dev/null)
346 # this is run in a sub-shell, so we can't use _hg_status
359 # this is run in a sub-shell, so we can't use _hg_status
347 local files=$(cd "$root/.hg/patches" 2>/dev/null &&
360 local files=$(cd "$root/.hg/patches" 2>/dev/null &&
348 "$hg" status -nmar 2>/dev/null)
361 "$hg" status -nmar 2>/dev/null)
349 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
362 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
350 }
363 }
351
364
352 _hg_cmd_qfold()
365 _hg_cmd_qfold()
353 {
366 {
354 _hg_ext_mq_patchlist qunapplied
367 _hg_ext_mq_patchlist qunapplied
355 }
368 }
356
369
357 _hg_cmd_qrename()
370 _hg_cmd_qrename()
358 {
371 {
359 _hg_ext_mq_patchlist qseries
372 _hg_ext_mq_patchlist qseries
360 }
373 }
361
374
362 _hg_cmd_qheader()
375 _hg_cmd_qheader()
363 {
376 {
364 _hg_ext_mq_patchlist qseries
377 _hg_ext_mq_patchlist qseries
365 }
378 }
366
379
367 _hg_cmd_qclone()
380 _hg_cmd_qclone()
368 {
381 {
369 local count=$(_hg_count_non_option)
382 local count=$(_hg_count_non_option)
370 if [ $count = 1 ]; then
383 if [ $count = 1 ]; then
371 _hg_paths
384 _hg_paths
372 fi
385 fi
373 _hg_repos
386 _hg_repos
374 }
387 }
375
388
376 _hg_ext_mq_guards()
389 _hg_ext_mq_guards()
377 {
390 {
378 "$hg" qselect --series 2>/dev/null | sed -e 's/^.//'
391 "$hg" qselect --series 2>/dev/null | sed -e 's/^.//'
379 }
392 }
380
393
381 _hg_cmd_qselect()
394 _hg_cmd_qselect()
382 {
395 {
383 local guards=$(_hg_ext_mq_guards)
396 local guards=$(_hg_ext_mq_guards)
384 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur"))
397 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur"))
385 }
398 }
386
399
387 _hg_cmd_qguard()
400 _hg_cmd_qguard()
388 {
401 {
389 local prefix=''
402 local prefix=''
390
403
391 if [[ "$cur" == +* ]]; then
404 if [[ "$cur" == +* ]]; then
392 prefix=+
405 prefix=+
393 elif [[ "$cur" == -* ]]; then
406 elif [[ "$cur" == -* ]]; then
394 prefix=-
407 prefix=-
395 fi
408 fi
396 local ncur=${cur#[-+]}
409 local ncur=${cur#[-+]}
397
410
398 if ! [ "$prefix" ]; then
411 if ! [ "$prefix" ]; then
399 _hg_ext_mq_patchlist qseries
412 _hg_ext_mq_patchlist qseries
400 return
413 return
401 fi
414 fi
402
415
403 local guards=$(_hg_ext_mq_guards)
416 local guards=$(_hg_ext_mq_guards)
404 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur"))
417 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur"))
405 }
418 }
406
419
407 _hg_opt_qguard()
420 _hg_opt_qguard()
408 {
421 {
409 local i
422 local i
410 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
423 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
411 if [[ ${COMP_WORDS[i]} != -* ]]; then
424 if [[ ${COMP_WORDS[i]} != -* ]]; then
412 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
425 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
413 _hg_cmd_qguard
426 _hg_cmd_qguard
414 return 0
427 return 0
415 fi
428 fi
416 elif [ "${COMP_WORDS[i]}" = -- ]; then
429 elif [ "${COMP_WORDS[i]}" = -- ]; then
417 _hg_cmd_qguard
430 _hg_cmd_qguard
418 return 0
431 return 0
419 fi
432 fi
420 done
433 done
421 return 1
434 return 1
422 }
435 }
423
436
424
437
425 # hbisect
438 # hbisect
426 _hg_cmd_bisect()
439 _hg_cmd_bisect()
427 {
440 {
428 local i subcmd
441 local i subcmd
429
442
430 # find the sub-command
443 # find the sub-command
431 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
444 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
432 if [[ ${COMP_WORDS[i]} != -* ]]; then
445 if [[ ${COMP_WORDS[i]} != -* ]]; then
433 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
446 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
434 subcmd="${COMP_WORDS[i]}"
447 subcmd="${COMP_WORDS[i]}"
435 break
448 break
436 fi
449 fi
437 fi
450 fi
438 done
451 done
439
452
440 if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
453 if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
441 COMPREPLY=(${COMPREPLY[@]:-}
454 COMPREPLY=(${COMPREPLY[@]:-}
442 $(compgen -W 'bad good help init next reset' -- "$cur"))
455 $(compgen -W 'bad good help init next reset' -- "$cur"))
443 return
456 return
444 fi
457 fi
445
458
446 case "$subcmd" in
459 case "$subcmd" in
447 good|bad)
460 good|bad)
448 _hg_tags
461 _hg_tags
462 _hg_branches
449 ;;
463 ;;
450 esac
464 esac
451
465
452 return
466 return
453 }
467 }
454
468
455
469
456 # patchbomb
470 # patchbomb
457 _hg_cmd_email()
471 _hg_cmd_email()
458 {
472 {
459 case "$prev" in
473 case "$prev" in
460 -c|--cc|-t|--to|-f|--from|--bcc)
474 -c|--cc|-t|--to|-f|--from|--bcc)
461 # we need an e-mail address. let the user provide a function
475 # we need an e-mail address. let the user provide a function
462 # to get them
476 # to get them
463 if [ "$(type -t _hg_emails)" = function ]; then
477 if [ "$(type -t _hg_emails)" = function ]; then
464 local arg=to
478 local arg=to
465 if [[ "$prev" == @(-f|--from) ]]; then
479 if [[ "$prev" == @(-f|--from) ]]; then
466 arg=from
480 arg=from
467 fi
481 fi
468 local addresses=$(_hg_emails $arg)
482 local addresses=$(_hg_emails $arg)
469 COMPREPLY=(${COMPREPLY[@]:-}
483 COMPREPLY=(${COMPREPLY[@]:-}
470 $(compgen -W '$addresses' -- "$cur"))
484 $(compgen -W '$addresses' -- "$cur"))
471 fi
485 fi
472 return
486 return
473 ;;
487 ;;
474 -m|--mbox)
488 -m|--mbox)
475 # fallback to standard filename completion
489 # fallback to standard filename completion
476 return
490 return
477 ;;
491 ;;
478 -s|--subject)
492 -s|--subject)
479 # free form string
493 # free form string
480 return
494 return
481 ;;
495 ;;
482 esac
496 esac
483
497
484 _hg_tags
498 _hg_tags
499 _hg_branches
485 return
500 return
486 }
501 }
487
502
488
503
489 # gpg
504 # gpg
490 _hg_cmd_sign()
505 _hg_cmd_sign()
491 {
506 {
492 _hg_tags
507 _hg_tags
508 _hg_branches
493 }
509 }
494
510
495
511
496 # transplant
512 # transplant
497 _hg_cmd_transplant()
513 _hg_cmd_transplant()
498 {
514 {
499 case "$prev" in
515 case "$prev" in
500 -s|--source)
516 -s|--source)
501 _hg_paths
517 _hg_paths
502 _hg_repos
518 _hg_repos
503 return
519 return
504 ;;
520 ;;
505 --filter)
521 --filter)
506 # standard filename completion
522 # standard filename completion
507 return
523 return
508 ;;
524 ;;
509 esac
525 esac
510
526
511 # all other transplant options values and command parameters are revisions
527 # all other transplant options values and command parameters are revisions
512 _hg_tags
528 _hg_tags
529 _hg_branches
513 return
530 return
514 }
531 }
515
532
General Comments 0
You need to be logged in to leave comments. Login now