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