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