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