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