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