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