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