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