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