##// END OF EJS Templates
completion: selectively use debugpathcomplete in bash_completion...
Bryan O'Sullivan -
r18793:a821ec83 default
parent child Browse files
Show More
@@ -1,579 +1,587
1 # bash completion for the Mercurial distributed SCM -*- sh -*-
1 # bash completion for the Mercurial distributed SCM -*- sh -*-
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_cmd()
57 _hg_cmd()
58 {
58 {
59 HGPLAIN=1 "$hg" "$@" 2>/dev/null
59 HGPLAIN=1 "$hg" "$@" 2>/dev/null
60 }
60 }
61
61
62 _hg_commands()
62 _hg_commands()
63 {
63 {
64 local commands
64 local commands
65 commands="$(HGPLAINEXCEPT=alias _hg_cmd debugcomplete "$cur")" || commands=""
65 commands="$(HGPLAINEXCEPT=alias _hg_cmd debugcomplete "$cur")" || commands=""
66 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
66 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
67 }
67 }
68
68
69 _hg_paths()
69 _hg_paths()
70 {
70 {
71 local paths="$(_hg_cmd paths -q)"
71 local paths="$(_hg_cmd paths -q)"
72 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
72 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
73 }
73 }
74
74
75 _hg_repos()
75 _hg_repos()
76 {
76 {
77 local i
77 local i
78 for i in $(compgen -d -- "$cur"); do
78 for i in $(compgen -d -- "$cur"); do
79 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
79 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
80 done
80 done
81 }
81 }
82
82
83 _hg_debugpathcomplete()
84 {
85 local files="$(_hg_cmd debugpathcomplete $1 "$cur")"
86 local IFS=$'\n'
87 compopt -o filenames 2>/dev/null
88 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
89 }
90
83 _hg_status()
91 _hg_status()
84 {
92 {
85 local files="$(_hg_cmd status -n$1 "glob:$cur**")"
93 local files="$(_hg_cmd status -n$1 "glob:$cur**")"
86 local IFS=$'\n'
94 local IFS=$'\n'
87 compopt -o filenames 2>/dev/null
95 compopt -o filenames 2>/dev/null
88 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
96 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
89 }
97 }
90
98
91 _hg_bookmarks()
99 _hg_bookmarks()
92 {
100 {
93 local bookmarks="$(_hg_cmd bookmarks -q)"
101 local bookmarks="$(_hg_cmd bookmarks -q)"
94 local IFS=$'\n'
102 local IFS=$'\n'
95 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur"))
103 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur"))
96 }
104 }
97
105
98 _hg_labels()
106 _hg_labels()
99 {
107 {
100 local labels="$(_hg_cmd debuglabelcomplete "$cur")"
108 local labels="$(_hg_cmd debuglabelcomplete "$cur")"
101 local IFS=$'\n'
109 local IFS=$'\n'
102 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$labels' -- "$cur"))
110 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$labels' -- "$cur"))
103 }
111 }
104
112
105 # this is "kind of" ugly...
113 # this is "kind of" ugly...
106 _hg_count_non_option()
114 _hg_count_non_option()
107 {
115 {
108 local i count=0
116 local i count=0
109 local filters="$1"
117 local filters="$1"
110
118
111 for ((i=1; $i<=$COMP_CWORD; i++)); do
119 for ((i=1; $i<=$COMP_CWORD; i++)); do
112 if [[ "${COMP_WORDS[i]}" != -* ]]; then
120 if [[ "${COMP_WORDS[i]}" != -* ]]; then
113 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
121 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
114 continue
122 continue
115 fi
123 fi
116 count=$(($count + 1))
124 count=$(($count + 1))
117 fi
125 fi
118 done
126 done
119
127
120 echo $(($count - 1))
128 echo $(($count - 1))
121 }
129 }
122
130
123 _hg()
131 _hg()
124 {
132 {
125 local cur prev cmd cmd_index opts i
133 local cur prev cmd cmd_index opts i
126 # global options that receive an argument
134 # global options that receive an argument
127 local global_args='--cwd|-R|--repository'
135 local global_args='--cwd|-R|--repository'
128 local hg="$1"
136 local hg="$1"
129 local canonical=0
137 local canonical=0
130
138
131 COMPREPLY=()
139 COMPREPLY=()
132 cur="$2"
140 cur="$2"
133 prev="$3"
141 prev="$3"
134
142
135 # searching for the command
143 # searching for the command
136 # (first non-option argument that doesn't follow a global option that
144 # (first non-option argument that doesn't follow a global option that
137 # receives an argument)
145 # receives an argument)
138 for ((i=1; $i<=$COMP_CWORD; i++)); do
146 for ((i=1; $i<=$COMP_CWORD; i++)); do
139 if [[ ${COMP_WORDS[i]} != -* ]]; then
147 if [[ ${COMP_WORDS[i]} != -* ]]; then
140 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
148 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
141 cmd="${COMP_WORDS[i]}"
149 cmd="${COMP_WORDS[i]}"
142 cmd_index=$i
150 cmd_index=$i
143 break
151 break
144 fi
152 fi
145 fi
153 fi
146 done
154 done
147
155
148 if [[ "$cur" == -* ]]; then
156 if [[ "$cur" == -* ]]; then
149 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
157 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
150 return
158 return
151 fi
159 fi
152
160
153 opts=$(_hg_cmd debugcomplete --options "$cmd")
161 opts=$(_hg_cmd debugcomplete --options "$cmd")
154
162
155 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
163 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
156 return
164 return
157 fi
165 fi
158
166
159 # global options
167 # global options
160 case "$prev" in
168 case "$prev" in
161 -R|--repository)
169 -R|--repository)
162 _hg_paths
170 _hg_paths
163 _hg_repos
171 _hg_repos
164 return
172 return
165 ;;
173 ;;
166 --cwd)
174 --cwd)
167 # Stick with default bash completion
175 # Stick with default bash completion
168 return
176 return
169 ;;
177 ;;
170 esac
178 esac
171
179
172 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
180 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
173 _hg_commands
181 _hg_commands
174 return
182 return
175 fi
183 fi
176
184
177 # try to generate completion candidates for whatever command the user typed
185 # try to generate completion candidates for whatever command the user typed
178 local help
186 local help
179 if _hg_command_specific; then
187 if _hg_command_specific; then
180 return
188 return
181 fi
189 fi
182
190
183 # canonicalize the command name and try again
191 # canonicalize the command name and try again
184 help=$(_hg_cmd help "$cmd")
192 help=$(_hg_cmd help "$cmd")
185 if [ $? -ne 0 ]; then
193 if [ $? -ne 0 ]; then
186 # Probably either the command doesn't exist or it's ambiguous
194 # Probably either the command doesn't exist or it's ambiguous
187 return
195 return
188 fi
196 fi
189 cmd=${help#hg }
197 cmd=${help#hg }
190 cmd=${cmd%%[$' \n']*}
198 cmd=${cmd%%[$' \n']*}
191 canonical=1
199 canonical=1
192 _hg_command_specific
200 _hg_command_specific
193 }
201 }
194
202
195 _hg_command_specific()
203 _hg_command_specific()
196 {
204 {
197 if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
205 if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
198 "_hg_cmd_$cmd"
206 "_hg_cmd_$cmd"
199 return 0
207 return 0
200 fi
208 fi
201
209
202 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
210 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
203 if [ $canonical = 1 ]; then
211 if [ $canonical = 1 ]; then
204 _hg_labels
212 _hg_labels
205 return 0
213 return 0
206 elif [[ status != "$cmd"* ]]; then
214 elif [[ status != "$cmd"* ]]; then
207 _hg_labels
215 _hg_labels
208 return 0
216 return 0
209 else
217 else
210 return 1
218 return 1
211 fi
219 fi
212 fi
220 fi
213
221
214 case "$cmd" in
222 case "$cmd" in
215 help)
223 help)
216 _hg_commands
224 _hg_commands
217 ;;
225 ;;
218 export)
226 export)
219 if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
227 if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
220 return 0
228 return 0
221 fi
229 fi
222 _hg_labels
230 _hg_labels
223 ;;
231 ;;
224 manifest|update)
232 manifest|update)
225 _hg_labels
233 _hg_labels
226 ;;
234 ;;
227 pull|push|outgoing|incoming)
235 pull|push|outgoing|incoming)
228 _hg_paths
236 _hg_paths
229 _hg_repos
237 _hg_repos
230 ;;
238 ;;
231 paths)
239 paths)
232 _hg_paths
240 _hg_paths
233 ;;
241 ;;
234 add)
242 add)
235 _hg_status "u"
243 _hg_status "u"
236 ;;
244 ;;
237 merge)
245 merge)
238 _hg_labels
246 _hg_labels
239 ;;
247 ;;
240 commit|record)
248 commit|record)
241 _hg_status "mar"
249 _hg_status "mar"
242 ;;
250 ;;
243 remove)
251 remove)
244 _hg_status "mcd"
252 _hg_debugpathcomplete -n
245 ;;
253 ;;
246 forget)
254 forget)
247 _hg_status "a"
255 _hg_debugpathcomplete -fa
248 ;;
256 ;;
249 diff)
257 diff)
250 _hg_status "mar"
258 _hg_status "mar"
251 ;;
259 ;;
252 revert)
260 revert)
253 _hg_status "mard"
261 _hg_debugpathcomplete
254 ;;
262 ;;
255 clone)
263 clone)
256 local count=$(_hg_count_non_option)
264 local count=$(_hg_count_non_option)
257 if [ $count = 1 ]; then
265 if [ $count = 1 ]; then
258 _hg_paths
266 _hg_paths
259 fi
267 fi
260 _hg_repos
268 _hg_repos
261 ;;
269 ;;
262 debugindex|debugindexdot)
270 debugindex|debugindexdot)
263 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
271 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
264 ;;
272 ;;
265 debugdata)
273 debugdata)
266 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
274 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
267 ;;
275 ;;
268 *)
276 *)
269 return 1
277 return 1
270 ;;
278 ;;
271 esac
279 esac
272
280
273 return 0
281 return 0
274 }
282 }
275
283
276 complete -o bashdefault -o default -F _hg hg \
284 complete -o bashdefault -o default -F _hg hg \
277 || complete -o default -F _hg hg
285 || complete -o default -F _hg hg
278
286
279
287
280 # Completion for commands provided by extensions
288 # Completion for commands provided by extensions
281
289
282 # bookmarks
290 # bookmarks
283 _hg_cmd_bookmarks()
291 _hg_cmd_bookmarks()
284 {
292 {
285 if [[ "$prev" = @(-d|--delete|-m|--rename) ]]; then
293 if [[ "$prev" = @(-d|--delete|-m|--rename) ]]; then
286 _hg_bookmarks
294 _hg_bookmarks
287 return
295 return
288 fi
296 fi
289 }
297 }
290
298
291 # mq
299 # mq
292 _hg_ext_mq_patchlist()
300 _hg_ext_mq_patchlist()
293 {
301 {
294 local patches
302 local patches
295 patches=$(_hg_cmd $1)
303 patches=$(_hg_cmd $1)
296 if [ $? -eq 0 ] && [ "$patches" ]; then
304 if [ $? -eq 0 ] && [ "$patches" ]; then
297 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
305 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
298 return 0
306 return 0
299 fi
307 fi
300 return 1
308 return 1
301 }
309 }
302
310
303 _hg_ext_mq_queues()
311 _hg_ext_mq_queues()
304 {
312 {
305 local root=$(_hg_cmd root)
313 local root=$(_hg_cmd root)
306 local n
314 local n
307 for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
315 for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
308 # I think we're usually not interested in the regular "patches" queue
316 # I think we're usually not interested in the regular "patches" queue
309 # so just filter it.
317 # so just filter it.
310 if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
318 if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
311 COMPREPLY=(${COMPREPLY[@]:-} "$n")
319 COMPREPLY=(${COMPREPLY[@]:-} "$n")
312 fi
320 fi
313 done
321 done
314 }
322 }
315
323
316 _hg_cmd_qpop()
324 _hg_cmd_qpop()
317 {
325 {
318 if [[ "$prev" = @(-n|--name) ]]; then
326 if [[ "$prev" = @(-n|--name) ]]; then
319 _hg_ext_mq_queues
327 _hg_ext_mq_queues
320 return
328 return
321 fi
329 fi
322 _hg_ext_mq_patchlist qapplied
330 _hg_ext_mq_patchlist qapplied
323 }
331 }
324
332
325 _hg_cmd_qpush()
333 _hg_cmd_qpush()
326 {
334 {
327 if [[ "$prev" = @(-n|--name) ]]; then
335 if [[ "$prev" = @(-n|--name) ]]; then
328 _hg_ext_mq_queues
336 _hg_ext_mq_queues
329 return
337 return
330 fi
338 fi
331 _hg_ext_mq_patchlist qunapplied
339 _hg_ext_mq_patchlist qunapplied
332 }
340 }
333
341
334 _hg_cmd_qgoto()
342 _hg_cmd_qgoto()
335 {
343 {
336 if [[ "$prev" = @(-n|--name) ]]; then
344 if [[ "$prev" = @(-n|--name) ]]; then
337 _hg_ext_mq_queues
345 _hg_ext_mq_queues
338 return
346 return
339 fi
347 fi
340 _hg_ext_mq_patchlist qseries
348 _hg_ext_mq_patchlist qseries
341 }
349 }
342
350
343 _hg_cmd_qdelete()
351 _hg_cmd_qdelete()
344 {
352 {
345 local qcmd=qunapplied
353 local qcmd=qunapplied
346 if [[ "$prev" = @(-r|--rev) ]]; then
354 if [[ "$prev" = @(-r|--rev) ]]; then
347 qcmd=qapplied
355 qcmd=qapplied
348 fi
356 fi
349 _hg_ext_mq_patchlist $qcmd
357 _hg_ext_mq_patchlist $qcmd
350 }
358 }
351
359
352 _hg_cmd_qfinish()
360 _hg_cmd_qfinish()
353 {
361 {
354 if [[ "$prev" = @(-a|--applied) ]]; then
362 if [[ "$prev" = @(-a|--applied) ]]; then
355 return
363 return
356 fi
364 fi
357 _hg_ext_mq_patchlist qapplied
365 _hg_ext_mq_patchlist qapplied
358 }
366 }
359
367
360 _hg_cmd_qsave()
368 _hg_cmd_qsave()
361 {
369 {
362 if [[ "$prev" = @(-n|--name) ]]; then
370 if [[ "$prev" = @(-n|--name) ]]; then
363 _hg_ext_mq_queues
371 _hg_ext_mq_queues
364 return
372 return
365 fi
373 fi
366 }
374 }
367
375
368 _hg_cmd_rebase() {
376 _hg_cmd_rebase() {
369 if [[ "$prev" = @(-s|--source|-d|--dest|-b|--base|-r|--rev) ]]; then
377 if [[ "$prev" = @(-s|--source|-d|--dest|-b|--base|-r|--rev) ]]; then
370 _hg_labels
378 _hg_labels
371 return
379 return
372 fi
380 fi
373 }
381 }
374
382
375 _hg_cmd_strip()
383 _hg_cmd_strip()
376 {
384 {
377 _hg_labels
385 _hg_labels
378 }
386 }
379
387
380 _hg_cmd_qcommit()
388 _hg_cmd_qcommit()
381 {
389 {
382 local root=$(_hg_cmd root)
390 local root=$(_hg_cmd root)
383 # this is run in a sub-shell, so we can't use _hg_status
391 # this is run in a sub-shell, so we can't use _hg_status
384 local files=$(cd "$root/.hg/patches" && _hg_cmd status -nmar)
392 local files=$(cd "$root/.hg/patches" && _hg_cmd status -nmar)
385 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
393 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
386 }
394 }
387
395
388 _hg_cmd_qfold()
396 _hg_cmd_qfold()
389 {
397 {
390 _hg_ext_mq_patchlist qunapplied
398 _hg_ext_mq_patchlist qunapplied
391 }
399 }
392
400
393 _hg_cmd_qrename()
401 _hg_cmd_qrename()
394 {
402 {
395 _hg_ext_mq_patchlist qseries
403 _hg_ext_mq_patchlist qseries
396 }
404 }
397
405
398 _hg_cmd_qheader()
406 _hg_cmd_qheader()
399 {
407 {
400 _hg_ext_mq_patchlist qseries
408 _hg_ext_mq_patchlist qseries
401 }
409 }
402
410
403 _hg_cmd_qclone()
411 _hg_cmd_qclone()
404 {
412 {
405 local count=$(_hg_count_non_option)
413 local count=$(_hg_count_non_option)
406 if [ $count = 1 ]; then
414 if [ $count = 1 ]; then
407 _hg_paths
415 _hg_paths
408 fi
416 fi
409 _hg_repos
417 _hg_repos
410 }
418 }
411
419
412 _hg_ext_mq_guards()
420 _hg_ext_mq_guards()
413 {
421 {
414 _hg_cmd qselect --series | sed -e 's/^.//'
422 _hg_cmd qselect --series | sed -e 's/^.//'
415 }
423 }
416
424
417 _hg_cmd_qselect()
425 _hg_cmd_qselect()
418 {
426 {
419 local guards=$(_hg_ext_mq_guards)
427 local guards=$(_hg_ext_mq_guards)
420 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur"))
428 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur"))
421 }
429 }
422
430
423 _hg_cmd_qguard()
431 _hg_cmd_qguard()
424 {
432 {
425 local prefix=''
433 local prefix=''
426
434
427 if [[ "$cur" == +* ]]; then
435 if [[ "$cur" == +* ]]; then
428 prefix=+
436 prefix=+
429 elif [[ "$cur" == -* ]]; then
437 elif [[ "$cur" == -* ]]; then
430 prefix=-
438 prefix=-
431 fi
439 fi
432 local ncur=${cur#[-+]}
440 local ncur=${cur#[-+]}
433
441
434 if ! [ "$prefix" ]; then
442 if ! [ "$prefix" ]; then
435 _hg_ext_mq_patchlist qseries
443 _hg_ext_mq_patchlist qseries
436 return
444 return
437 fi
445 fi
438
446
439 local guards=$(_hg_ext_mq_guards)
447 local guards=$(_hg_ext_mq_guards)
440 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur"))
448 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur"))
441 }
449 }
442
450
443 _hg_opt_qguard()
451 _hg_opt_qguard()
444 {
452 {
445 local i
453 local i
446 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
454 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
447 if [[ ${COMP_WORDS[i]} != -* ]]; then
455 if [[ ${COMP_WORDS[i]} != -* ]]; then
448 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
456 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
449 _hg_cmd_qguard
457 _hg_cmd_qguard
450 return 0
458 return 0
451 fi
459 fi
452 elif [ "${COMP_WORDS[i]}" = -- ]; then
460 elif [ "${COMP_WORDS[i]}" = -- ]; then
453 _hg_cmd_qguard
461 _hg_cmd_qguard
454 return 0
462 return 0
455 fi
463 fi
456 done
464 done
457 return 1
465 return 1
458 }
466 }
459
467
460 _hg_cmd_qqueue()
468 _hg_cmd_qqueue()
461 {
469 {
462 local q
470 local q
463 local queues
471 local queues
464 local opts="--list --create --rename --delete --purge"
472 local opts="--list --create --rename --delete --purge"
465
473
466 queues=$( _hg_cmd qqueue --quiet )
474 queues=$( _hg_cmd qqueue --quiet )
467
475
468 COMPREPLY=( $( compgen -W "${opts} ${queues}" "${cur}" ) )
476 COMPREPLY=( $( compgen -W "${opts} ${queues}" "${cur}" ) )
469 }
477 }
470
478
471
479
472 # hbisect
480 # hbisect
473 _hg_cmd_bisect()
481 _hg_cmd_bisect()
474 {
482 {
475 local i subcmd
483 local i subcmd
476
484
477 # find the sub-command
485 # find the sub-command
478 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
486 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
479 if [[ ${COMP_WORDS[i]} != -* ]]; then
487 if [[ ${COMP_WORDS[i]} != -* ]]; then
480 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
488 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
481 subcmd="${COMP_WORDS[i]}"
489 subcmd="${COMP_WORDS[i]}"
482 break
490 break
483 fi
491 fi
484 fi
492 fi
485 done
493 done
486
494
487 if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
495 if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
488 COMPREPLY=(${COMPREPLY[@]:-}
496 COMPREPLY=(${COMPREPLY[@]:-}
489 $(compgen -W 'bad good help init next reset' -- "$cur"))
497 $(compgen -W 'bad good help init next reset' -- "$cur"))
490 return
498 return
491 fi
499 fi
492
500
493 case "$subcmd" in
501 case "$subcmd" in
494 good|bad)
502 good|bad)
495 _hg_labels
503 _hg_labels
496 ;;
504 ;;
497 esac
505 esac
498
506
499 return
507 return
500 }
508 }
501
509
502
510
503 # patchbomb
511 # patchbomb
504 _hg_cmd_email()
512 _hg_cmd_email()
505 {
513 {
506 case "$prev" in
514 case "$prev" in
507 -c|--cc|-t|--to|-f|--from|--bcc)
515 -c|--cc|-t|--to|-f|--from|--bcc)
508 # we need an e-mail address. let the user provide a function
516 # we need an e-mail address. let the user provide a function
509 # to get them
517 # to get them
510 if [ "$(type -t _hg_emails)" = function ]; then
518 if [ "$(type -t _hg_emails)" = function ]; then
511 local arg=to
519 local arg=to
512 if [[ "$prev" == @(-f|--from) ]]; then
520 if [[ "$prev" == @(-f|--from) ]]; then
513 arg=from
521 arg=from
514 fi
522 fi
515 local addresses=$(_hg_emails $arg)
523 local addresses=$(_hg_emails $arg)
516 COMPREPLY=(${COMPREPLY[@]:-}
524 COMPREPLY=(${COMPREPLY[@]:-}
517 $(compgen -W '$addresses' -- "$cur"))
525 $(compgen -W '$addresses' -- "$cur"))
518 fi
526 fi
519 return
527 return
520 ;;
528 ;;
521 -m|--mbox)
529 -m|--mbox)
522 # fallback to standard filename completion
530 # fallback to standard filename completion
523 return
531 return
524 ;;
532 ;;
525 -s|--subject)
533 -s|--subject)
526 # free form string
534 # free form string
527 return
535 return
528 ;;
536 ;;
529 esac
537 esac
530
538
531 _hg_labels
539 _hg_labels
532 return
540 return
533 }
541 }
534
542
535
543
536 # gpg
544 # gpg
537 _hg_cmd_sign()
545 _hg_cmd_sign()
538 {
546 {
539 _hg_labels
547 _hg_labels
540 }
548 }
541
549
542
550
543 # transplant
551 # transplant
544 _hg_cmd_transplant()
552 _hg_cmd_transplant()
545 {
553 {
546 case "$prev" in
554 case "$prev" in
547 -s|--source)
555 -s|--source)
548 _hg_paths
556 _hg_paths
549 _hg_repos
557 _hg_repos
550 return
558 return
551 ;;
559 ;;
552 --filter)
560 --filter)
553 # standard filename completion
561 # standard filename completion
554 return
562 return
555 ;;
563 ;;
556 esac
564 esac
557
565
558 # all other transplant options values and command parameters are revisions
566 # all other transplant options values and command parameters are revisions
559 _hg_labels
567 _hg_labels
560 return
568 return
561 }
569 }
562
570
563 # shelve
571 # shelve
564 _hg_shelves()
572 _hg_shelves()
565 {
573 {
566 local shelves="$(_hg_cmd unshelve -l .)"
574 local shelves="$(_hg_cmd unshelve -l .)"
567 local IFS=$'\n'
575 local IFS=$'\n'
568 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$shelves' -- "$cur"))
576 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$shelves' -- "$cur"))
569 }
577 }
570
578
571 _hg_cmd_shelve()
579 _hg_cmd_shelve()
572 {
580 {
573 _hg_status "mard"
581 _hg_status "mard"
574 }
582 }
575
583
576 _hg_cmd_unshelve()
584 _hg_cmd_unshelve()
577 {
585 {
578 _hg_shelves
586 _hg_shelves
579 }
587 }
General Comments 0
You need to be logged in to leave comments. Login now