##// END OF EJS Templates
bash/zsh completion: use HGPLAIN when invoking hg (issue2297)
Brodie Rao -
r11646:91af149b stable
parent child Browse files
Show More
@@ -1,573 +1,577 b''
1 # bash completion for the Mercurial distributed SCM
1 # bash completion for the Mercurial distributed SCM
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()
58 {
59 HGPLAIN=1 "$hg" "$@" 2>/dev/null
60 }
61
57 _hg_commands()
62 _hg_commands()
58 {
63 {
59 local commands
64 local commands
60 commands="$("$hg" debugcomplete "$cur" 2>/dev/null)" || commands=""
65 commands="$(_hg_cmd debugcomplete "$cur")" || commands=""
61 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
66 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
62 }
67 }
63
68
64 _hg_paths()
69 _hg_paths()
65 {
70 {
66 local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')"
71 local paths="$(_hg_cmd paths | sed -e 's/ = .*$//')"
67 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
72 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
68 }
73 }
69
74
70 _hg_repos()
75 _hg_repos()
71 {
76 {
72 local i
77 local i
73 for i in $(compgen -d -- "$cur"); do
78 for i in $(compgen -d -- "$cur"); do
74 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
79 test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
75 done
80 done
76 }
81 }
77
82
78 _hg_status()
83 _hg_status()
79 {
84 {
80 local files="$("$hg" status -n$1 . 2>/dev/null)"
85 local files="$(_hg_cmd status -n$1 .)"
81 local IFS=$'\n'
86 local IFS=$'\n'
82 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
87 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
83 }
88 }
84
89
85 _hg_tags()
90 _hg_tags()
86 {
91 {
87 local tags="$("$hg" tags -q 2>/dev/null)"
92 local tags="$(_hg_cmd tags -q)"
88 local IFS=$'\n'
93 local IFS=$'\n'
89 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
94 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
90 }
95 }
91
96
92 _hg_branches()
97 _hg_branches()
93 {
98 {
94 local branches="$("$hg" branches -q 2>/dev/null)"
99 local branches="$(_hg_cmd branches -q)"
95 local IFS=$'\n'
100 local IFS=$'\n'
96 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$branches' -- "$cur"))
101 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$branches' -- "$cur"))
97 }
102 }
98
103
99 # this is "kind of" ugly...
104 # this is "kind of" ugly...
100 _hg_count_non_option()
105 _hg_count_non_option()
101 {
106 {
102 local i count=0
107 local i count=0
103 local filters="$1"
108 local filters="$1"
104
109
105 for ((i=1; $i<=$COMP_CWORD; i++)); do
110 for ((i=1; $i<=$COMP_CWORD; i++)); do
106 if [[ "${COMP_WORDS[i]}" != -* ]]; then
111 if [[ "${COMP_WORDS[i]}" != -* ]]; then
107 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
112 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
108 continue
113 continue
109 fi
114 fi
110 count=$(($count + 1))
115 count=$(($count + 1))
111 fi
116 fi
112 done
117 done
113
118
114 echo $(($count - 1))
119 echo $(($count - 1))
115 }
120 }
116
121
117 _hg()
122 _hg()
118 {
123 {
119 local cur prev cmd cmd_index opts i
124 local cur prev cmd cmd_index opts i
120 # global options that receive an argument
125 # global options that receive an argument
121 local global_args='--cwd|-R|--repository'
126 local global_args='--cwd|-R|--repository'
122 local hg="$1"
127 local hg="$1"
123 local canonical=0
128 local canonical=0
124
129
125 COMPREPLY=()
130 COMPREPLY=()
126 cur="$2"
131 cur="$2"
127 prev="$3"
132 prev="$3"
128
133
129 # searching for the command
134 # searching for the command
130 # (first non-option argument that doesn't follow a global option that
135 # (first non-option argument that doesn't follow a global option that
131 # receives an argument)
136 # receives an argument)
132 for ((i=1; $i<=$COMP_CWORD; i++)); do
137 for ((i=1; $i<=$COMP_CWORD; i++)); do
133 if [[ ${COMP_WORDS[i]} != -* ]]; then
138 if [[ ${COMP_WORDS[i]} != -* ]]; then
134 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
139 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
135 cmd="${COMP_WORDS[i]}"
140 cmd="${COMP_WORDS[i]}"
136 cmd_index=$i
141 cmd_index=$i
137 break
142 break
138 fi
143 fi
139 fi
144 fi
140 done
145 done
141
146
142 if [[ "$cur" == -* ]]; then
147 if [[ "$cur" == -* ]]; then
143 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
148 if [ "$(type -t "_hg_opt_$cmd")" = function ] && "_hg_opt_$cmd"; then
144 return
149 return
145 fi
150 fi
146
151
147 opts=$("$hg" debugcomplete --options "$cmd" 2>/dev/null)
152 opts=$(_hg_cmd debugcomplete --options "$cmd")
148
153
149 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
154 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
150 return
155 return
151 fi
156 fi
152
157
153 # global options
158 # global options
154 case "$prev" in
159 case "$prev" in
155 -R|--repository)
160 -R|--repository)
156 _hg_paths
161 _hg_paths
157 _hg_repos
162 _hg_repos
158 return
163 return
159 ;;
164 ;;
160 --cwd)
165 --cwd)
161 # Stick with default bash completion
166 # Stick with default bash completion
162 return
167 return
163 ;;
168 ;;
164 esac
169 esac
165
170
166 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
171 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
167 _hg_commands
172 _hg_commands
168 return
173 return
169 fi
174 fi
170
175
171 # try to generate completion candidates for whatever command the user typed
176 # try to generate completion candidates for whatever command the user typed
172 local help
177 local help
173 if _hg_command_specific; then
178 if _hg_command_specific; then
174 return
179 return
175 fi
180 fi
176
181
177 # canonicalize the command name and try again
182 # canonicalize the command name and try again
178 help=$("$hg" help "$cmd" 2>/dev/null)
183 help=$(_hg_cmd help "$cmd")
179 if [ $? -ne 0 ]; then
184 if [ $? -ne 0 ]; then
180 # Probably either the command doesn't exist or it's ambiguous
185 # Probably either the command doesn't exist or it's ambiguous
181 return
186 return
182 fi
187 fi
183 cmd=${help#hg }
188 cmd=${help#hg }
184 cmd=${cmd%%[$' \n']*}
189 cmd=${cmd%%[$' \n']*}
185 canonical=1
190 canonical=1
186 _hg_command_specific
191 _hg_command_specific
187 }
192 }
188
193
189 _hg_command_specific()
194 _hg_command_specific()
190 {
195 {
191 if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
196 if [ "$(type -t "_hg_cmd_$cmd")" = function ]; then
192 "_hg_cmd_$cmd"
197 "_hg_cmd_$cmd"
193 return 0
198 return 0
194 fi
199 fi
195
200
196 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
201 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" == --rev ]; then
197 if [ $canonical = 1 ]; then
202 if [ $canonical = 1 ]; then
198 _hg_tags
203 _hg_tags
199 _hg_branches
204 _hg_branches
200 return 0
205 return 0
201 elif [[ status != "$cmd"* ]]; then
206 elif [[ status != "$cmd"* ]]; then
202 _hg_tags
207 _hg_tags
203 _hg_branches
208 _hg_branches
204 return 0
209 return 0
205 else
210 else
206 return 1
211 return 1
207 fi
212 fi
208 fi
213 fi
209
214
210 case "$cmd" in
215 case "$cmd" in
211 help)
216 help)
212 _hg_commands
217 _hg_commands
213 ;;
218 ;;
214 export)
219 export)
215 if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
220 if _hg_ext_mq_patchlist qapplied && [ "${COMPREPLY[*]}" ]; then
216 return 0
221 return 0
217 fi
222 fi
218 _hg_tags
223 _hg_tags
219 _hg_branches
224 _hg_branches
220 ;;
225 ;;
221 manifest|update)
226 manifest|update)
222 _hg_tags
227 _hg_tags
223 _hg_branches
228 _hg_branches
224 ;;
229 ;;
225 pull|push|outgoing|incoming)
230 pull|push|outgoing|incoming)
226 _hg_paths
231 _hg_paths
227 _hg_repos
232 _hg_repos
228 ;;
233 ;;
229 paths)
234 paths)
230 _hg_paths
235 _hg_paths
231 ;;
236 ;;
232 add)
237 add)
233 _hg_status "u"
238 _hg_status "u"
234 ;;
239 ;;
235 merge)
240 merge)
236 _hg_tags
241 _hg_tags
237 _hg_branches
242 _hg_branches
238 ;;
243 ;;
239 commit)
244 commit)
240 _hg_status "mar"
245 _hg_status "mar"
241 ;;
246 ;;
242 remove)
247 remove)
243 _hg_status "d"
248 _hg_status "d"
244 ;;
249 ;;
245 forget)
250 forget)
246 _hg_status "a"
251 _hg_status "a"
247 ;;
252 ;;
248 diff)
253 diff)
249 _hg_status "mar"
254 _hg_status "mar"
250 ;;
255 ;;
251 revert)
256 revert)
252 _hg_status "mard"
257 _hg_status "mard"
253 ;;
258 ;;
254 clone)
259 clone)
255 local count=$(_hg_count_non_option)
260 local count=$(_hg_count_non_option)
256 if [ $count = 1 ]; then
261 if [ $count = 1 ]; then
257 _hg_paths
262 _hg_paths
258 fi
263 fi
259 _hg_repos
264 _hg_repos
260 ;;
265 ;;
261 debugindex|debugindexdot)
266 debugindex|debugindexdot)
262 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
267 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
263 ;;
268 ;;
264 debugdata)
269 debugdata)
265 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
270 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
266 ;;
271 ;;
267 *)
272 *)
268 return 1
273 return 1
269 ;;
274 ;;
270 esac
275 esac
271
276
272 return 0
277 return 0
273 }
278 }
274
279
275 complete -o bashdefault -o default -F _hg hg 2>/dev/null \
280 complete -o bashdefault -o default -F _hg hg \
276 || complete -o default -F _hg hg
281 || complete -o default -F _hg hg
277
282
278
283
279 # Completion for commands provided by extensions
284 # Completion for commands provided by extensions
280
285
281 # bookmarks
286 # bookmarks
282 _hg_bookmarks()
287 _hg_bookmarks()
283 {
288 {
284 local bookmarks="$("$hg" bookmarks --quiet 2>/dev/null )"
289 local bookmarks="$(_hg_cmd bookmarks --quiet )"
285 local IFS=$'\n'
290 local IFS=$'\n'
286 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur"))
291 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$bookmarks' -- "$cur"))
287 }
292 }
288
293
289 _hg_cmd_bookmarks()
294 _hg_cmd_bookmarks()
290 {
295 {
291 if [[ "$prev" = @(-d|--delete|-m|--rename) ]]; then
296 if [[ "$prev" = @(-d|--delete|-m|--rename) ]]; then
292 _hg_bookmarks
297 _hg_bookmarks
293 return
298 return
294 fi
299 fi
295 }
300 }
296
301
297 # mq
302 # mq
298 _hg_ext_mq_patchlist()
303 _hg_ext_mq_patchlist()
299 {
304 {
300 local patches
305 local patches
301 patches=$("$hg" $1 2>/dev/null)
306 patches=$(_hg_cmd $1)
302 if [ $? -eq 0 ] && [ "$patches" ]; then
307 if [ $? -eq 0 ] && [ "$patches" ]; then
303 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
308 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$patches' -- "$cur"))
304 return 0
309 return 0
305 fi
310 fi
306 return 1
311 return 1
307 }
312 }
308
313
309 _hg_ext_mq_queues()
314 _hg_ext_mq_queues()
310 {
315 {
311 local root=$("$hg" root 2>/dev/null)
316 local root=$(_hg_cmd root)
312 local n
317 local n
313 for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
318 for n in $(cd "$root"/.hg && compgen -d -- "$cur"); do
314 # I think we're usually not interested in the regular "patches" queue
319 # I think we're usually not interested in the regular "patches" queue
315 # so just filter it.
320 # so just filter it.
316 if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
321 if [ "$n" != patches ] && [ -e "$root/.hg/$n/series" ]; then
317 COMPREPLY=(${COMPREPLY[@]:-} "$n")
322 COMPREPLY=(${COMPREPLY[@]:-} "$n")
318 fi
323 fi
319 done
324 done
320 }
325 }
321
326
322 _hg_cmd_qpop()
327 _hg_cmd_qpop()
323 {
328 {
324 if [[ "$prev" = @(-n|--name) ]]; then
329 if [[ "$prev" = @(-n|--name) ]]; then
325 _hg_ext_mq_queues
330 _hg_ext_mq_queues
326 return
331 return
327 fi
332 fi
328 _hg_ext_mq_patchlist qapplied
333 _hg_ext_mq_patchlist qapplied
329 }
334 }
330
335
331 _hg_cmd_qpush()
336 _hg_cmd_qpush()
332 {
337 {
333 if [[ "$prev" = @(-n|--name) ]]; then
338 if [[ "$prev" = @(-n|--name) ]]; then
334 _hg_ext_mq_queues
339 _hg_ext_mq_queues
335 return
340 return
336 fi
341 fi
337 _hg_ext_mq_patchlist qunapplied
342 _hg_ext_mq_patchlist qunapplied
338 }
343 }
339
344
340 _hg_cmd_qgoto()
345 _hg_cmd_qgoto()
341 {
346 {
342 if [[ "$prev" = @(-n|--name) ]]; then
347 if [[ "$prev" = @(-n|--name) ]]; then
343 _hg_ext_mq_queues
348 _hg_ext_mq_queues
344 return
349 return
345 fi
350 fi
346 _hg_ext_mq_patchlist qseries
351 _hg_ext_mq_patchlist qseries
347 }
352 }
348
353
349 _hg_cmd_qdelete()
354 _hg_cmd_qdelete()
350 {
355 {
351 local qcmd=qunapplied
356 local qcmd=qunapplied
352 if [[ "$prev" = @(-r|--rev) ]]; then
357 if [[ "$prev" = @(-r|--rev) ]]; then
353 qcmd=qapplied
358 qcmd=qapplied
354 fi
359 fi
355 _hg_ext_mq_patchlist $qcmd
360 _hg_ext_mq_patchlist $qcmd
356 }
361 }
357
362
358 _hg_cmd_qfinish()
363 _hg_cmd_qfinish()
359 {
364 {
360 if [[ "$prev" = @(-a|--applied) ]]; then
365 if [[ "$prev" = @(-a|--applied) ]]; then
361 return
366 return
362 fi
367 fi
363 _hg_ext_mq_patchlist qapplied
368 _hg_ext_mq_patchlist qapplied
364 }
369 }
365
370
366 _hg_cmd_qsave()
371 _hg_cmd_qsave()
367 {
372 {
368 if [[ "$prev" = @(-n|--name) ]]; then
373 if [[ "$prev" = @(-n|--name) ]]; then
369 _hg_ext_mq_queues
374 _hg_ext_mq_queues
370 return
375 return
371 fi
376 fi
372 }
377 }
373
378
374 _hg_cmd_strip()
379 _hg_cmd_strip()
375 {
380 {
376 _hg_tags
381 _hg_tags
377 _hg_branches
382 _hg_branches
378 }
383 }
379
384
380 _hg_cmd_qcommit()
385 _hg_cmd_qcommit()
381 {
386 {
382 local root=$("$hg" root 2>/dev/null)
387 local root=$(_hg_cmd root)
383 # this is run in a sub-shell, so we can't use _hg_status
388 # this is run in a sub-shell, so we can't use _hg_status
384 local files=$(cd "$root/.hg/patches" 2>/dev/null &&
389 local files=$(cd "$root/.hg/patches" && _hg_cmd status -nmar)
385 "$hg" status -nmar 2>/dev/null)
386 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
390 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
387 }
391 }
388
392
389 _hg_cmd_qfold()
393 _hg_cmd_qfold()
390 {
394 {
391 _hg_ext_mq_patchlist qunapplied
395 _hg_ext_mq_patchlist qunapplied
392 }
396 }
393
397
394 _hg_cmd_qrename()
398 _hg_cmd_qrename()
395 {
399 {
396 _hg_ext_mq_patchlist qseries
400 _hg_ext_mq_patchlist qseries
397 }
401 }
398
402
399 _hg_cmd_qheader()
403 _hg_cmd_qheader()
400 {
404 {
401 _hg_ext_mq_patchlist qseries
405 _hg_ext_mq_patchlist qseries
402 }
406 }
403
407
404 _hg_cmd_qclone()
408 _hg_cmd_qclone()
405 {
409 {
406 local count=$(_hg_count_non_option)
410 local count=$(_hg_count_non_option)
407 if [ $count = 1 ]; then
411 if [ $count = 1 ]; then
408 _hg_paths
412 _hg_paths
409 fi
413 fi
410 _hg_repos
414 _hg_repos
411 }
415 }
412
416
413 _hg_ext_mq_guards()
417 _hg_ext_mq_guards()
414 {
418 {
415 "$hg" qselect --series 2>/dev/null | sed -e 's/^.//'
419 _hg_cmd qselect --series | sed -e 's/^.//'
416 }
420 }
417
421
418 _hg_cmd_qselect()
422 _hg_cmd_qselect()
419 {
423 {
420 local guards=$(_hg_ext_mq_guards)
424 local guards=$(_hg_ext_mq_guards)
421 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur"))
425 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$guards' -- "$cur"))
422 }
426 }
423
427
424 _hg_cmd_qguard()
428 _hg_cmd_qguard()
425 {
429 {
426 local prefix=''
430 local prefix=''
427
431
428 if [[ "$cur" == +* ]]; then
432 if [[ "$cur" == +* ]]; then
429 prefix=+
433 prefix=+
430 elif [[ "$cur" == -* ]]; then
434 elif [[ "$cur" == -* ]]; then
431 prefix=-
435 prefix=-
432 fi
436 fi
433 local ncur=${cur#[-+]}
437 local ncur=${cur#[-+]}
434
438
435 if ! [ "$prefix" ]; then
439 if ! [ "$prefix" ]; then
436 _hg_ext_mq_patchlist qseries
440 _hg_ext_mq_patchlist qseries
437 return
441 return
438 fi
442 fi
439
443
440 local guards=$(_hg_ext_mq_guards)
444 local guards=$(_hg_ext_mq_guards)
441 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur"))
445 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -P $prefix -W '$guards' -- "$ncur"))
442 }
446 }
443
447
444 _hg_opt_qguard()
448 _hg_opt_qguard()
445 {
449 {
446 local i
450 local i
447 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
451 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
448 if [[ ${COMP_WORDS[i]} != -* ]]; then
452 if [[ ${COMP_WORDS[i]} != -* ]]; then
449 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
453 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
450 _hg_cmd_qguard
454 _hg_cmd_qguard
451 return 0
455 return 0
452 fi
456 fi
453 elif [ "${COMP_WORDS[i]}" = -- ]; then
457 elif [ "${COMP_WORDS[i]}" = -- ]; then
454 _hg_cmd_qguard
458 _hg_cmd_qguard
455 return 0
459 return 0
456 fi
460 fi
457 done
461 done
458 return 1
462 return 1
459 }
463 }
460
464
461
465
462 # hbisect
466 # hbisect
463 _hg_cmd_bisect()
467 _hg_cmd_bisect()
464 {
468 {
465 local i subcmd
469 local i subcmd
466
470
467 # find the sub-command
471 # find the sub-command
468 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
472 for ((i=cmd_index+1; i<=COMP_CWORD; i++)); do
469 if [[ ${COMP_WORDS[i]} != -* ]]; then
473 if [[ ${COMP_WORDS[i]} != -* ]]; then
470 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
474 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
471 subcmd="${COMP_WORDS[i]}"
475 subcmd="${COMP_WORDS[i]}"
472 break
476 break
473 fi
477 fi
474 fi
478 fi
475 done
479 done
476
480
477 if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
481 if [ -z "$subcmd" ] || [ $COMP_CWORD -eq $i ] || [ "$subcmd" = help ]; then
478 COMPREPLY=(${COMPREPLY[@]:-}
482 COMPREPLY=(${COMPREPLY[@]:-}
479 $(compgen -W 'bad good help init next reset' -- "$cur"))
483 $(compgen -W 'bad good help init next reset' -- "$cur"))
480 return
484 return
481 fi
485 fi
482
486
483 case "$subcmd" in
487 case "$subcmd" in
484 good|bad)
488 good|bad)
485 _hg_tags
489 _hg_tags
486 _hg_branches
490 _hg_branches
487 ;;
491 ;;
488 esac
492 esac
489
493
490 return
494 return
491 }
495 }
492
496
493
497
494 # patchbomb
498 # patchbomb
495 _hg_cmd_email()
499 _hg_cmd_email()
496 {
500 {
497 case "$prev" in
501 case "$prev" in
498 -c|--cc|-t|--to|-f|--from|--bcc)
502 -c|--cc|-t|--to|-f|--from|--bcc)
499 # we need an e-mail address. let the user provide a function
503 # we need an e-mail address. let the user provide a function
500 # to get them
504 # to get them
501 if [ "$(type -t _hg_emails)" = function ]; then
505 if [ "$(type -t _hg_emails)" = function ]; then
502 local arg=to
506 local arg=to
503 if [[ "$prev" == @(-f|--from) ]]; then
507 if [[ "$prev" == @(-f|--from) ]]; then
504 arg=from
508 arg=from
505 fi
509 fi
506 local addresses=$(_hg_emails $arg)
510 local addresses=$(_hg_emails $arg)
507 COMPREPLY=(${COMPREPLY[@]:-}
511 COMPREPLY=(${COMPREPLY[@]:-}
508 $(compgen -W '$addresses' -- "$cur"))
512 $(compgen -W '$addresses' -- "$cur"))
509 fi
513 fi
510 return
514 return
511 ;;
515 ;;
512 -m|--mbox)
516 -m|--mbox)
513 # fallback to standard filename completion
517 # fallback to standard filename completion
514 return
518 return
515 ;;
519 ;;
516 -s|--subject)
520 -s|--subject)
517 # free form string
521 # free form string
518 return
522 return
519 ;;
523 ;;
520 esac
524 esac
521
525
522 _hg_tags
526 _hg_tags
523 _hg_branches
527 _hg_branches
524 return
528 return
525 }
529 }
526
530
527
531
528 # gpg
532 # gpg
529 _hg_cmd_sign()
533 _hg_cmd_sign()
530 {
534 {
531 _hg_tags
535 _hg_tags
532 _hg_branches
536 _hg_branches
533 }
537 }
534
538
535
539
536 # transplant
540 # transplant
537 _hg_cmd_transplant()
541 _hg_cmd_transplant()
538 {
542 {
539 case "$prev" in
543 case "$prev" in
540 -s|--source)
544 -s|--source)
541 _hg_paths
545 _hg_paths
542 _hg_repos
546 _hg_repos
543 return
547 return
544 ;;
548 ;;
545 --filter)
549 --filter)
546 # standard filename completion
550 # standard filename completion
547 return
551 return
548 ;;
552 ;;
549 esac
553 esac
550
554
551 # all other transplant options values and command parameters are revisions
555 # all other transplant options values and command parameters are revisions
552 _hg_tags
556 _hg_tags
553 _hg_branches
557 _hg_branches
554 return
558 return
555 }
559 }
556
560
557 # shelve
561 # shelve
558 _hg_shelves()
562 _hg_shelves()
559 {
563 {
560 local shelves="$("$hg" unshelve -l . 2>/dev/null)"
564 local shelves="$(_hg_cmd unshelve -l .)"
561 local IFS=$'\n'
565 local IFS=$'\n'
562 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$shelves' -- "$cur"))
566 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$shelves' -- "$cur"))
563 }
567 }
564
568
565 _hg_cmd_shelve()
569 _hg_cmd_shelve()
566 {
570 {
567 _hg_status "mard"
571 _hg_status "mard"
568 }
572 }
569
573
570 _hg_cmd_unshelve()
574 _hg_cmd_unshelve()
571 {
575 {
572 _hg_shelves
576 _hg_shelves
573 }
577 }
@@ -1,951 +1,950 b''
1 #compdef hg
1 #compdef hg
2
2
3 # Zsh completion script for mercurial. Rename this file to _hg and copy
3 # Zsh completion script for mercurial. Rename this file to _hg and copy
4 # it into your zsh function path (/usr/share/zsh/site-functions for
4 # it into your zsh function path (/usr/share/zsh/site-functions for
5 # instance)
5 # instance)
6 #
6 #
7 # If you do not want to install it globally, you can copy it somewhere
7 # If you do not want to install it globally, you can copy it somewhere
8 # else and add that directory to $fpath. This must be done before
8 # else and add that directory to $fpath. This must be done before
9 # compinit is called. If the file is copied to ~/.zsh.d, your ~/.zshrc
9 # compinit is called. If the file is copied to ~/.zsh.d, your ~/.zshrc
10 # file could look like this:
10 # file could look like this:
11 #
11 #
12 # fpath=("$HOME/.zsh.d" $fpath)
12 # fpath=("$HOME/.zsh.d" $fpath)
13 # autoload -U compinit
13 # autoload -U compinit
14 # compinit
14 # compinit
15 #
15 #
16 # Copyright (C) 2005, 2006 Steve Borho <steve@borho.org>
16 # Copyright (C) 2005, 2006 Steve Borho <steve@borho.org>
17 # Copyright (C) 2006-9 Brendan Cully <brendan@kublai.com>
17 # Copyright (C) 2006-9 Brendan Cully <brendan@kublai.com>
18 #
18 #
19 # Permission is hereby granted, without written agreement and without
19 # Permission is hereby granted, without written agreement and without
20 # licence or royalty fees, to use, copy, modify, and distribute this
20 # licence or royalty fees, to use, copy, modify, and distribute this
21 # software and to distribute modified versions of this software for any
21 # software and to distribute modified versions of this software for any
22 # purpose, provided that the above copyright notice and the following
22 # purpose, provided that the above copyright notice and the following
23 # two paragraphs appear in all copies of this software.
23 # two paragraphs appear in all copies of this software.
24 #
24 #
25 # In no event shall the authors be liable to any party for direct,
25 # In no event shall the authors be liable to any party for direct,
26 # indirect, special, incidental, or consequential damages arising out of
26 # indirect, special, incidental, or consequential damages arising out of
27 # the use of this software and its documentation, even if the authors
27 # the use of this software and its documentation, even if the authors
28 # have been advised of the possibility of such damage.
28 # have been advised of the possibility of such damage.
29 #
29 #
30 # The authors specifically disclaim any warranties, including, but not
30 # The authors specifically disclaim any warranties, including, but not
31 # limited to, the implied warranties of merchantability and fitness for
31 # limited to, the implied warranties of merchantability and fitness for
32 # a particular purpose. The software provided hereunder is on an "as
32 # a particular purpose. The software provided hereunder is on an "as
33 # is" basis, and the authors have no obligation to provide maintenance,
33 # is" basis, and the authors have no obligation to provide maintenance,
34 # support, updates, enhancements, or modifications.
34 # support, updates, enhancements, or modifications.
35
35
36 emulate -LR zsh
36 emulate -LR zsh
37 setopt extendedglob
37 setopt extendedglob
38
38
39 local curcontext="$curcontext" state line
39 local curcontext="$curcontext" state line
40 typeset -A _hg_cmd_globals
40 typeset -A _hg_cmd_globals
41
41
42 _hg() {
42 _hg() {
43 local cmd _hg_root
43 local cmd _hg_root
44 integer i=2
44 integer i=2
45 _hg_cmd_globals=()
45 _hg_cmd_globals=()
46
46
47 while (( i < $#words ))
47 while (( i < $#words ))
48 do
48 do
49 case "$words[$i]" in
49 case "$words[$i]" in
50 -R|--repository)
50 -R|--repository)
51 eval _hg_root="$words[$i+1]"
51 eval _hg_root="$words[$i+1]"
52 _hg_cmd_globals+=("$words[$i]" "$_hg_root")
52 _hg_cmd_globals+=("$words[$i]" "$_hg_root")
53 (( i += 2 ))
53 (( i += 2 ))
54 continue
54 continue
55 ;;
55 ;;
56 -R*)
56 -R*)
57 _hg_cmd_globals+="$words[$i]"
57 _hg_cmd_globals+="$words[$i]"
58 eval _hg_root="${words[$i]#-R}"
58 eval _hg_root="${words[$i]#-R}"
59 (( i++ ))
59 (( i++ ))
60 continue
60 continue
61 ;;
61 ;;
62 --cwd|--config)
62 --cwd|--config)
63 # pass along arguments to hg completer
63 # pass along arguments to hg completer
64 _hg_cmd_globals+=("$words[$i]" "$words[$i+1]")
64 _hg_cmd_globals+=("$words[$i]" "$words[$i+1]")
65 (( i += 2 ))
65 (( i += 2 ))
66 continue
66 continue
67 ;;
67 ;;
68 -*)
68 -*)
69 # skip option
69 # skip option
70 (( i++ ))
70 (( i++ ))
71 continue
71 continue
72 ;;
72 ;;
73 esac
73 esac
74 if [[ -z "$cmd" ]]
74 if [[ -z "$cmd" ]]
75 then
75 then
76 cmd="$words[$i]"
76 cmd="$words[$i]"
77 words[$i]=()
77 words[$i]=()
78 (( CURRENT-- ))
78 (( CURRENT-- ))
79 fi
79 fi
80 (( i++ ))
80 (( i++ ))
81 done
81 done
82
82
83 if [[ -z "$cmd" ]]
83 if [[ -z "$cmd" ]]
84 then
84 then
85 _arguments -s -w : $_hg_global_opts \
85 _arguments -s -w : $_hg_global_opts \
86 ':mercurial command:_hg_commands'
86 ':mercurial command:_hg_commands'
87 return
87 return
88 fi
88 fi
89
89
90 # resolve abbreviations and aliases
90 # resolve abbreviations and aliases
91 if ! (( $+functions[_hg_cmd_${cmd}] ))
91 if ! (( $+functions[_hg_cmd_${cmd}] ))
92 then
92 then
93 local cmdexp
93 local cmdexp
94 (( $#_hg_cmd_list )) || _hg_get_commands
94 (( $#_hg_cmd_list )) || _hg_get_commands
95
95
96 cmdexp=$_hg_cmd_list[(r)${cmd}*]
96 cmdexp=$_hg_cmd_list[(r)${cmd}*]
97 if [[ $cmdexp == $_hg_cmd_list[(R)${cmd}*] ]]
97 if [[ $cmdexp == $_hg_cmd_list[(R)${cmd}*] ]]
98 then
98 then
99 # might be nice to rewrite the command line with the expansion
99 # might be nice to rewrite the command line with the expansion
100 cmd="$cmdexp"
100 cmd="$cmdexp"
101 fi
101 fi
102 if [[ -n $_hg_alias_list[$cmd] ]]
102 if [[ -n $_hg_alias_list[$cmd] ]]
103 then
103 then
104 cmd=$_hg_alias_list[$cmd]
104 cmd=$_hg_alias_list[$cmd]
105 fi
105 fi
106 fi
106 fi
107
107
108 curcontext="${curcontext%:*:*}:hg-${cmd}:"
108 curcontext="${curcontext%:*:*}:hg-${cmd}:"
109
109
110 zstyle -s ":completion:$curcontext:" cache-policy update_policy
110 zstyle -s ":completion:$curcontext:" cache-policy update_policy
111
111
112 if [[ -z "$update_policy" ]]
112 if [[ -z "$update_policy" ]]
113 then
113 then
114 zstyle ":completion:$curcontext:" cache-policy _hg_cache_policy
114 zstyle ":completion:$curcontext:" cache-policy _hg_cache_policy
115 fi
115 fi
116
116
117 if (( $+functions[_hg_cmd_${cmd}] ))
117 if (( $+functions[_hg_cmd_${cmd}] ))
118 then
118 then
119 _hg_cmd_${cmd}
119 _hg_cmd_${cmd}
120 else
120 else
121 # complete unknown commands normally
121 # complete unknown commands normally
122 _arguments -s -w : $_hg_global_opts \
122 _arguments -s -w : $_hg_global_opts \
123 '*:files:_hg_files'
123 '*:files:_hg_files'
124 fi
124 fi
125 }
125 }
126
126
127 _hg_cache_policy() {
127 _hg_cache_policy() {
128 typeset -a old
128 typeset -a old
129
129
130 # cache for a minute
130 # cache for a minute
131 old=( "$1"(mm+10) )
131 old=( "$1"(mm+10) )
132 (( $#old )) && return 0
132 (( $#old )) && return 0
133
133
134 return 1
134 return 1
135 }
135 }
136
136
137 _hg_get_commands() {
137 _hg_get_commands() {
138 typeset -ga _hg_cmd_list
138 typeset -ga _hg_cmd_list
139 typeset -gA _hg_alias_list
139 typeset -gA _hg_alias_list
140 local hline cmd cmdalias
140 local hline cmd cmdalias
141
141
142 _call_program hg hg debugcomplete -v | while read -A hline
142 _call_program hg hg debugcomplete -v | while read -A hline
143 do
143 do
144 cmd=$hline[1]
144 cmd=$hline[1]
145 _hg_cmd_list+=($cmd)
145 _hg_cmd_list+=($cmd)
146
146
147 for cmdalias in $hline[2,-1]
147 for cmdalias in $hline[2,-1]
148 do
148 do
149 _hg_cmd_list+=($cmdalias)
149 _hg_cmd_list+=($cmdalias)
150 _hg_alias_list+=($cmdalias $cmd)
150 _hg_alias_list+=($cmdalias $cmd)
151 done
151 done
152 done
152 done
153 }
153 }
154
154
155 _hg_commands() {
155 _hg_commands() {
156 (( $#_hg_cmd_list )) || _hg_get_commands
156 (( $#_hg_cmd_list )) || _hg_get_commands
157 _describe -t commands 'mercurial command' _hg_cmd_list
157 _describe -t commands 'mercurial command' _hg_cmd_list
158 }
158 }
159
159
160 _hg_revrange() {
160 _hg_revrange() {
161 compset -P 1 '*:'
161 compset -P 1 '*:'
162 _hg_tags "$@"
162 _hg_tags "$@"
163 }
163 }
164
164
165 _hg_tags() {
165 _hg_tags() {
166 typeset -a tags
166 typeset -a tags
167 local tag rev
167 local tag rev
168
168
169 _hg_cmd tags | while read tag
169 _hg_cmd tags | while read tag
170 do
170 do
171 tags+=(${tag/ # [0-9]#:*})
171 tags+=(${tag/ # [0-9]#:*})
172 done
172 done
173 (( $#tags )) && _describe -t tags 'tags' tags
173 (( $#tags )) && _describe -t tags 'tags' tags
174 }
174 }
175
175
176 # likely merge candidates
176 # likely merge candidates
177 _hg_mergerevs() {
177 _hg_mergerevs() {
178 typeset -a heads
178 typeset -a heads
179 local myrev
179 local myrev
180
180
181 heads=(${(f)"$(_hg_cmd heads --template '{rev}\\n')"})
181 heads=(${(f)"$(_hg_cmd heads --template '{rev}\\n')"})
182 # exclude own revision
182 # exclude own revision
183 myrev=$(_hg_cmd log -r . --template '{rev}\\n')
183 myrev=$(_hg_cmd log -r . --template '{rev}\\n')
184 heads=(${heads:#$myrev})
184 heads=(${heads:#$myrev})
185
185
186 (( $#heads )) && _describe -t heads 'heads' heads
186 (( $#heads )) && _describe -t heads 'heads' heads
187 }
187 }
188
188
189 _hg_files() {
189 _hg_files() {
190 if [[ -n "$_hg_root" ]]
190 if [[ -n "$_hg_root" ]]
191 then
191 then
192 [[ -d "$_hg_root/.hg" ]] || return
192 [[ -d "$_hg_root/.hg" ]] || return
193 case "$_hg_root" in
193 case "$_hg_root" in
194 /*)
194 /*)
195 _files -W $_hg_root
195 _files -W $_hg_root
196 ;;
196 ;;
197 *)
197 *)
198 _files -W $PWD/$_hg_root
198 _files -W $PWD/$_hg_root
199 ;;
199 ;;
200 esac
200 esac
201 else
201 else
202 _files
202 _files
203 fi
203 fi
204 }
204 }
205
205
206 _hg_status() {
206 _hg_status() {
207 [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
207 [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
208 status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX)"})
208 status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX)"})
209 }
209 }
210
210
211 _hg_unknown() {
211 _hg_unknown() {
212 typeset -a status_files
212 typeset -a status_files
213 _hg_status u
213 _hg_status u
214 _wanted files expl 'unknown files' _multi_parts / status_files
214 _wanted files expl 'unknown files' _multi_parts / status_files
215 }
215 }
216
216
217 _hg_missing() {
217 _hg_missing() {
218 typeset -a status_files
218 typeset -a status_files
219 _hg_status d
219 _hg_status d
220 _wanted files expl 'missing files' _multi_parts / status_files
220 _wanted files expl 'missing files' _multi_parts / status_files
221 }
221 }
222
222
223 _hg_modified() {
223 _hg_modified() {
224 typeset -a status_files
224 typeset -a status_files
225 _hg_status m
225 _hg_status m
226 _wanted files expl 'modified files' _multi_parts / status_files
226 _wanted files expl 'modified files' _multi_parts / status_files
227 }
227 }
228
228
229 _hg_resolve() {
229 _hg_resolve() {
230 local rstate rpath
230 local rstate rpath
231
231
232 [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
232 [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
233
233
234 _hg_cmd resolve -l ./$PREFIX | while read rstate rpath
234 _hg_cmd resolve -l ./$PREFIX | while read rstate rpath
235 do
235 do
236 [[ $rstate == 'R' ]] && resolved_files+=($rpath)
236 [[ $rstate == 'R' ]] && resolved_files+=($rpath)
237 [[ $rstate == 'U' ]] && unresolved_files+=($rpath)
237 [[ $rstate == 'U' ]] && unresolved_files+=($rpath)
238 done
238 done
239 }
239 }
240
240
241 _hg_resolved() {
241 _hg_resolved() {
242 typeset -a resolved_files unresolved_files
242 typeset -a resolved_files unresolved_files
243 _hg_resolve
243 _hg_resolve
244 _wanted files expl 'resolved files' _multi_parts / resolved_files
244 _wanted files expl 'resolved files' _multi_parts / resolved_files
245 }
245 }
246
246
247 _hg_unresolved() {
247 _hg_unresolved() {
248 typeset -a resolved_files unresolved_files
248 typeset -a resolved_files unresolved_files
249 _hg_resolve
249 _hg_resolve
250 _wanted files expl 'unresolved files' _multi_parts / unresolved_files
250 _wanted files expl 'unresolved files' _multi_parts / unresolved_files
251 }
251 }
252
252
253 _hg_config() {
253 _hg_config() {
254 typeset -a items
254 typeset -a items
255 items=(${${(%f)"$(_call_program hg hg showconfig)"}%%\=*})
255 items=(${${(%f)"$(_call_program hg hg showconfig)"}%%\=*})
256 (( $#items )) && _describe -t config 'config item' items
256 (( $#items )) && _describe -t config 'config item' items
257 }
257 }
258
258
259 _hg_addremove() {
259 _hg_addremove() {
260 _alternative 'files:unknown files:_hg_unknown' \
260 _alternative 'files:unknown files:_hg_unknown' \
261 'files:missing files:_hg_missing'
261 'files:missing files:_hg_missing'
262 }
262 }
263
263
264 _hg_ssh_urls() {
264 _hg_ssh_urls() {
265 if [[ -prefix */ ]]
265 if [[ -prefix */ ]]
266 then
266 then
267 if zstyle -T ":completion:${curcontext}:files" remote-access
267 if zstyle -T ":completion:${curcontext}:files" remote-access
268 then
268 then
269 local host=${PREFIX%%/*}
269 local host=${PREFIX%%/*}
270 typeset -a remdirs
270 typeset -a remdirs
271 compset -p $(( $#host + 1 ))
271 compset -p $(( $#host + 1 ))
272 local rempath=${(M)PREFIX##*/}
272 local rempath=${(M)PREFIX##*/}
273 local cacheid="hg:${host}-${rempath//\//_}"
273 local cacheid="hg:${host}-${rempath//\//_}"
274 cacheid=${cacheid%[-_]}
274 cacheid=${cacheid%[-_]}
275 compset -P '*/'
275 compset -P '*/'
276 if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid"
276 if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid"
277 then
277 then
278 remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}")"}##*/}%/})
278 remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}")"}##*/}%/})
279 _store_cache "$cacheid" remdirs
279 _store_cache "$cacheid" remdirs
280 fi
280 fi
281 _describe -t directories 'remote directory' remdirs -S/
281 _describe -t directories 'remote directory' remdirs -S/
282 else
282 else
283 _message 'remote directory'
283 _message 'remote directory'
284 fi
284 fi
285 else
285 else
286 if compset -P '*@'
286 if compset -P '*@'
287 then
287 then
288 _hosts -S/
288 _hosts -S/
289 else
289 else
290 _alternative 'hosts:remote host name:_hosts -S/' \
290 _alternative 'hosts:remote host name:_hosts -S/' \
291 'users:user:_users -S@'
291 'users:user:_users -S@'
292 fi
292 fi
293 fi
293 fi
294 }
294 }
295
295
296 _hg_urls() {
296 _hg_urls() {
297 if compset -P bundle://
297 if compset -P bundle://
298 then
298 then
299 _files
299 _files
300 elif compset -P ssh://
300 elif compset -P ssh://
301 then
301 then
302 _hg_ssh_urls
302 _hg_ssh_urls
303 elif [[ -prefix *: ]]
303 elif [[ -prefix *: ]]
304 then
304 then
305 _urls
305 _urls
306 else
306 else
307 local expl
307 local expl
308 compset -S '[^:]*'
308 compset -S '[^:]*'
309 _wanted url-schemas expl 'URL schema' compadd -S '' - \
309 _wanted url-schemas expl 'URL schema' compadd -S '' - \
310 http:// https:// ssh:// bundle://
310 http:// https:// ssh:// bundle://
311 fi
311 fi
312 }
312 }
313
313
314 _hg_paths() {
314 _hg_paths() {
315 typeset -a paths pnames
315 typeset -a paths pnames
316 _hg_cmd paths | while read -A pnames
316 _hg_cmd paths | while read -A pnames
317 do
317 do
318 paths+=($pnames[1])
318 paths+=($pnames[1])
319 done
319 done
320 (( $#paths )) && _describe -t path-aliases 'repository alias' paths
320 (( $#paths )) && _describe -t path-aliases 'repository alias' paths
321 }
321 }
322
322
323 _hg_remote() {
323 _hg_remote() {
324 _alternative 'path-aliases:repository alias:_hg_paths' \
324 _alternative 'path-aliases:repository alias:_hg_paths' \
325 'directories:directory:_files -/' \
325 'directories:directory:_files -/' \
326 'urls:URL:_hg_urls'
326 'urls:URL:_hg_urls'
327 }
327 }
328
328
329 _hg_clone_dest() {
329 _hg_clone_dest() {
330 _alternative 'directories:directory:_files -/' \
330 _alternative 'directories:directory:_files -/' \
331 'urls:URL:_hg_urls'
331 'urls:URL:_hg_urls'
332 }
332 }
333
333
334 # Common options
334 # Common options
335 _hg_global_opts=(
335 _hg_global_opts=(
336 '(--repository -R)'{-R+,--repository}'[repository root directory]:repository:_files -/'
336 '(--repository -R)'{-R+,--repository}'[repository root directory]:repository:_files -/'
337 '--cwd[change working directory]:new working directory:_files -/'
337 '--cwd[change working directory]:new working directory:_files -/'
338 '(--noninteractive -y)'{-y,--noninteractive}'[do not prompt, assume yes for any required answers]'
338 '(--noninteractive -y)'{-y,--noninteractive}'[do not prompt, assume yes for any required answers]'
339 '(--verbose -v)'{-v,--verbose}'[enable additional output]'
339 '(--verbose -v)'{-v,--verbose}'[enable additional output]'
340 '*--config[set/override config option]:defined config items:_hg_config'
340 '*--config[set/override config option]:defined config items:_hg_config'
341 '(--quiet -q)'{-q,--quiet}'[suppress output]'
341 '(--quiet -q)'{-q,--quiet}'[suppress output]'
342 '(--help -h)'{-h,--help}'[display help and exit]'
342 '(--help -h)'{-h,--help}'[display help and exit]'
343 '--debug[debug mode]'
343 '--debug[debug mode]'
344 '--debugger[start debugger]'
344 '--debugger[start debugger]'
345 '--encoding[set the charset encoding (default: UTF8)]'
345 '--encoding[set the charset encoding (default: UTF8)]'
346 '--encodingmode[set the charset encoding mode (default: strict)]'
346 '--encodingmode[set the charset encoding mode (default: strict)]'
347 '--lsprof[print improved command execution profile]'
347 '--lsprof[print improved command execution profile]'
348 '--traceback[print traceback on exception]'
348 '--traceback[print traceback on exception]'
349 '--time[time how long the command takes]'
349 '--time[time how long the command takes]'
350 '--profile[profile]'
350 '--profile[profile]'
351 '--version[output version information and exit]'
351 '--version[output version information and exit]'
352 )
352 )
353
353
354 _hg_pat_opts=(
354 _hg_pat_opts=(
355 '*'{-I+,--include}'[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
355 '*'{-I+,--include}'[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
356 '*'{-X+,--exclude}'[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/')
356 '*'{-X+,--exclude}'[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/')
357
357
358 _hg_diff_opts=(
358 _hg_diff_opts=(
359 '(--text -a)'{-a,--text}'[treat all files as text]'
359 '(--text -a)'{-a,--text}'[treat all files as text]'
360 '(--git -g)'{-g,--git}'[use git extended diff format]'
360 '(--git -g)'{-g,--git}'[use git extended diff format]'
361 "--nodates[omit dates from diff headers]")
361 "--nodates[omit dates from diff headers]")
362
362
363 _hg_dryrun_opts=(
363 _hg_dryrun_opts=(
364 '(--dry-run -n)'{-n,--dry-run}'[do not perform actions, just print output]')
364 '(--dry-run -n)'{-n,--dry-run}'[do not perform actions, just print output]')
365
365
366 _hg_style_opts=(
366 _hg_style_opts=(
367 '--style[display using template map file]:'
367 '--style[display using template map file]:'
368 '--template[display with template]:')
368 '--template[display with template]:')
369
369
370 _hg_commit_opts=(
370 _hg_commit_opts=(
371 '(-m --message -l --logfile --edit -e)'{-e,--edit}'[edit commit message]'
371 '(-m --message -l --logfile --edit -e)'{-e,--edit}'[edit commit message]'
372 '(-e --edit -l --logfile --message -m)'{-m+,--message}'[use <text> as commit message]:message:'
372 '(-e --edit -l --logfile --message -m)'{-m+,--message}'[use <text> as commit message]:message:'
373 '(-e --edit -m --message --logfile -l)'{-l+,--logfile}'[read the commit message from <file>]:log file:_files')
373 '(-e --edit -m --message --logfile -l)'{-l+,--logfile}'[read the commit message from <file>]:log file:_files')
374
374
375 _hg_remote_opts=(
375 _hg_remote_opts=(
376 '(--ssh -e)'{-e+,--ssh}'[specify ssh command to use]:'
376 '(--ssh -e)'{-e+,--ssh}'[specify ssh command to use]:'
377 '--remotecmd[specify hg command to run on the remote side]:')
377 '--remotecmd[specify hg command to run on the remote side]:')
378
378
379 _hg_cmd() {
379 _hg_cmd() {
380 _call_program hg hg --config ui.verbose=0 --config defaults."$1"= \
380 _call_program hg HGPLAIN=1 hg "$_hg_cmd_globals[@]" "$@" 2> /dev/null
381 "$_hg_cmd_globals[@]" "$@" 2> /dev/null
382 }
381 }
383
382
384 _hg_cmd_add() {
383 _hg_cmd_add() {
385 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
384 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
386 '*:unknown files:_hg_unknown'
385 '*:unknown files:_hg_unknown'
387 }
386 }
388
387
389 _hg_cmd_addremove() {
388 _hg_cmd_addremove() {
390 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
389 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
391 '(--similarity -s)'{-s+,--similarity}'[guess renamed files by similarity (0<=s<=100)]:' \
390 '(--similarity -s)'{-s+,--similarity}'[guess renamed files by similarity (0<=s<=100)]:' \
392 '*:unknown or missing files:_hg_addremove'
391 '*:unknown or missing files:_hg_addremove'
393 }
392 }
394
393
395 _hg_cmd_annotate() {
394 _hg_cmd_annotate() {
396 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
395 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
397 '(--rev -r)'{-r+,--rev}'[annotate the specified revision]:revision:_hg_tags' \
396 '(--rev -r)'{-r+,--rev}'[annotate the specified revision]:revision:_hg_tags' \
398 '(--follow -f)'{-f,--follow}'[follow file copies and renames]' \
397 '(--follow -f)'{-f,--follow}'[follow file copies and renames]' \
399 '(--text -a)'{-a,--text}'[treat all files as text]' \
398 '(--text -a)'{-a,--text}'[treat all files as text]' \
400 '(--user -u)'{-u,--user}'[list the author]' \
399 '(--user -u)'{-u,--user}'[list the author]' \
401 '(--date -d)'{-d,--date}'[list the date]' \
400 '(--date -d)'{-d,--date}'[list the date]' \
402 '(--number -n)'{-n,--number}'[list the revision number (default)]' \
401 '(--number -n)'{-n,--number}'[list the revision number (default)]' \
403 '(--changeset -c)'{-c,--changeset}'[list the changeset]' \
402 '(--changeset -c)'{-c,--changeset}'[list the changeset]' \
404 '*:files:_hg_files'
403 '*:files:_hg_files'
405 }
404 }
406
405
407 _hg_cmd_archive() {
406 _hg_cmd_archive() {
408 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
407 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
409 '--no-decode[do not pass files through decoders]' \
408 '--no-decode[do not pass files through decoders]' \
410 '(--prefix -p)'{-p+,--prefix}'[directory prefix for files in archive]:' \
409 '(--prefix -p)'{-p+,--prefix}'[directory prefix for files in archive]:' \
411 '(--rev -r)'{-r+,--rev}'[revision to distribute]:revision:_hg_tags' \
410 '(--rev -r)'{-r+,--rev}'[revision to distribute]:revision:_hg_tags' \
412 '(--type -t)'{-t+,--type}'[type of distribution to create]:archive type:(files tar tbz2 tgz uzip zip)' \
411 '(--type -t)'{-t+,--type}'[type of distribution to create]:archive type:(files tar tbz2 tgz uzip zip)' \
413 '*:destination:_files'
412 '*:destination:_files'
414 }
413 }
415
414
416 _hg_cmd_backout() {
415 _hg_cmd_backout() {
417 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
416 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
418 '--merge[merge with old dirstate parent after backout]' \
417 '--merge[merge with old dirstate parent after backout]' \
419 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
418 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
420 '--parent[parent to choose when backing out merge]' \
419 '--parent[parent to choose when backing out merge]' \
421 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
420 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
422 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
421 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
423 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
422 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
424 '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt'
423 '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt'
425 }
424 }
426
425
427 _hg_cmd_bisect() {
426 _hg_cmd_bisect() {
428 _arguments -s -w : $_hg_global_opts \
427 _arguments -s -w : $_hg_global_opts \
429 '(-)'{-r,--reset}'[reset bisect state]' \
428 '(-)'{-r,--reset}'[reset bisect state]' \
430 '(--good -g --bad -b --skip -s --reset -r)'{-g,--good}'[mark changeset good]'::revision:_hg_tags \
429 '(--good -g --bad -b --skip -s --reset -r)'{-g,--good}'[mark changeset good]'::revision:_hg_tags \
431 '(--good -g --bad -b --skip -s --reset -r)'{-b,--bad}'[mark changeset bad]'::revision:_hg_tags \
430 '(--good -g --bad -b --skip -s --reset -r)'{-b,--bad}'[mark changeset bad]'::revision:_hg_tags \
432 '(--good -g --bad -b --skip -s --reset -r)'{-s,--skip}'[skip testing changeset]' \
431 '(--good -g --bad -b --skip -s --reset -r)'{-s,--skip}'[skip testing changeset]' \
433 '(--command -c --noupdate -U)'{-c+,--command}'[use command to check changeset state]':commands:_command_names \
432 '(--command -c --noupdate -U)'{-c+,--command}'[use command to check changeset state]':commands:_command_names \
434 '(--command -c --noupdate -U)'{-U,--noupdate}'[do not update to target]'
433 '(--command -c --noupdate -U)'{-U,--noupdate}'[do not update to target]'
435 }
434 }
436
435
437 _hg_cmd_branch() {
436 _hg_cmd_branch() {
438 _arguments -s -w : $_hg_global_opts \
437 _arguments -s -w : $_hg_global_opts \
439 '(--force -f)'{-f,--force}'[set branch name even if it shadows an existing branch]' \
438 '(--force -f)'{-f,--force}'[set branch name even if it shadows an existing branch]' \
440 '(--clean -C)'{-C,--clean}'[reset branch name to parent branch name]'
439 '(--clean -C)'{-C,--clean}'[reset branch name to parent branch name]'
441 }
440 }
442
441
443 _hg_cmd_branches() {
442 _hg_cmd_branches() {
444 _arguments -s -w : $_hg_global_opts \
443 _arguments -s -w : $_hg_global_opts \
445 '(--active -a)'{-a,--active}'[show only branches that have unmerge heads]'
444 '(--active -a)'{-a,--active}'[show only branches that have unmerge heads]'
446 }
445 }
447
446
448 _hg_cmd_bundle() {
447 _hg_cmd_bundle() {
449 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
448 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
450 '(--force -f)'{-f,--force}'[run even when remote repository is unrelated]' \
449 '(--force -f)'{-f,--force}'[run even when remote repository is unrelated]' \
451 '(2)*--base[a base changeset to specify instead of a destination]:revision:_hg_tags' \
450 '(2)*--base[a base changeset to specify instead of a destination]:revision:_hg_tags' \
452 ':output file:_files' \
451 ':output file:_files' \
453 ':destination repository:_files -/'
452 ':destination repository:_files -/'
454 }
453 }
455
454
456 _hg_cmd_cat() {
455 _hg_cmd_cat() {
457 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
456 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
458 '(--output -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
457 '(--output -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
459 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
458 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
460 '*:file:_hg_files'
459 '*:file:_hg_files'
461 }
460 }
462
461
463 _hg_cmd_clone() {
462 _hg_cmd_clone() {
464 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
463 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
465 '(--noupdate -U)'{-U,--noupdate}'[do not update the new working directory]' \
464 '(--noupdate -U)'{-U,--noupdate}'[do not update the new working directory]' \
466 '(--rev -r)'{-r+,--rev}'[a changeset you would like to have after cloning]:' \
465 '(--rev -r)'{-r+,--rev}'[a changeset you would like to have after cloning]:' \
467 '--uncompressed[use uncompressed transfer (fast over LAN)]' \
466 '--uncompressed[use uncompressed transfer (fast over LAN)]' \
468 ':source repository:_hg_remote' \
467 ':source repository:_hg_remote' \
469 ':destination:_hg_clone_dest'
468 ':destination:_hg_clone_dest'
470 }
469 }
471
470
472 _hg_cmd_commit() {
471 _hg_cmd_commit() {
473 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
472 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
474 '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]' \
473 '(--addremove -A)'{-A,--addremove}'[mark new/missing files as added/removed before committing]' \
475 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
474 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
476 '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt' \
475 '(--logfile -l)'{-l+,--logfile}'[read commit message from <file>]:log file:_files -g \*.txt' \
477 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
476 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
478 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
477 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
479 '*:file:_hg_files'
478 '*:file:_hg_files'
480 }
479 }
481
480
482 _hg_cmd_copy() {
481 _hg_cmd_copy() {
483 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
482 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
484 '(--after -A)'{-A,--after}'[record a copy that has already occurred]' \
483 '(--after -A)'{-A,--after}'[record a copy that has already occurred]' \
485 '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
484 '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
486 '*:file:_hg_files'
485 '*:file:_hg_files'
487 }
486 }
488
487
489 _hg_cmd_diff() {
488 _hg_cmd_diff() {
490 typeset -A opt_args
489 typeset -A opt_args
491 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_diff_opts \
490 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_diff_opts \
492 '*'{-r,--rev}'+[revision]:revision:_hg_revrange' \
491 '*'{-r,--rev}'+[revision]:revision:_hg_revrange' \
493 '(--show-function -p)'{-p,--show-function}'[show which function each change is in]' \
492 '(--show-function -p)'{-p,--show-function}'[show which function each change is in]' \
494 '(--ignore-all-space -w)'{-w,--ignore-all-space}'[ignore white space when comparing lines]' \
493 '(--ignore-all-space -w)'{-w,--ignore-all-space}'[ignore white space when comparing lines]' \
495 '(--ignore-space-change -b)'{-b,--ignore-space-change}'[ignore changes in the amount of white space]' \
494 '(--ignore-space-change -b)'{-b,--ignore-space-change}'[ignore changes in the amount of white space]' \
496 '(--ignore-blank-lines -B)'{-B,--ignore-blank-lines}'[ignore changes whose lines are all blank]' \
495 '(--ignore-blank-lines -B)'{-B,--ignore-blank-lines}'[ignore changes whose lines are all blank]' \
497 '*:file:->diff_files'
496 '*:file:->diff_files'
498
497
499 if [[ $state == 'diff_files' ]]
498 if [[ $state == 'diff_files' ]]
500 then
499 then
501 if [[ -n $opt_args[-r] ]]
500 if [[ -n $opt_args[-r] ]]
502 then
501 then
503 _hg_files
502 _hg_files
504 else
503 else
505 _hg_modified
504 _hg_modified
506 fi
505 fi
507 fi
506 fi
508 }
507 }
509
508
510 _hg_cmd_export() {
509 _hg_cmd_export() {
511 _arguments -s -w : $_hg_global_opts $_hg_diff_opts \
510 _arguments -s -w : $_hg_global_opts $_hg_diff_opts \
512 '(--outout -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
511 '(--outout -o)'{-o+,--output}'[print output to file with formatted name]:filespec:' \
513 '--switch-parent[diff against the second parent]' \
512 '--switch-parent[diff against the second parent]' \
514 '*:revision:_hg_tags'
513 '*:revision:_hg_tags'
515 }
514 }
516
515
517 _hg_cmd_grep() {
516 _hg_cmd_grep() {
518 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
517 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
519 '(--print0 -0)'{-0,--print0}'[end filenames with NUL]' \
518 '(--print0 -0)'{-0,--print0}'[end filenames with NUL]' \
520 '--all[print all revisions with matches]' \
519 '--all[print all revisions with matches]' \
521 '(--follow -f)'{-f,--follow}'[follow changeset or file history]' \
520 '(--follow -f)'{-f,--follow}'[follow changeset or file history]' \
522 '(--ignore-case -i)'{-i,--ignore-case}'[ignore case when matching]' \
521 '(--ignore-case -i)'{-i,--ignore-case}'[ignore case when matching]' \
523 '(--files-with-matches -l)'{-l,--files-with-matches}'[print only filenames and revs that match]' \
522 '(--files-with-matches -l)'{-l,--files-with-matches}'[print only filenames and revs that match]' \
524 '(--line-number -n)'{-n,--line-number}'[print matching line numbers]' \
523 '(--line-number -n)'{-n,--line-number}'[print matching line numbers]' \
525 '*'{-r+,--rev}'[search in given revision range]:revision:_hg_revrange' \
524 '*'{-r+,--rev}'[search in given revision range]:revision:_hg_revrange' \
526 '(--user -u)'{-u,--user}'[print user who committed change]' \
525 '(--user -u)'{-u,--user}'[print user who committed change]' \
527 '1:search pattern:' \
526 '1:search pattern:' \
528 '*:files:_hg_files'
527 '*:files:_hg_files'
529 }
528 }
530
529
531 _hg_cmd_heads() {
530 _hg_cmd_heads() {
532 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
531 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
533 '(--rev -r)'{-r+,--rev}'[show only heads which are descendants of rev]:revision:_hg_tags'
532 '(--rev -r)'{-r+,--rev}'[show only heads which are descendants of rev]:revision:_hg_tags'
534 }
533 }
535
534
536 _hg_cmd_help() {
535 _hg_cmd_help() {
537 _arguments -s -w : $_hg_global_opts \
536 _arguments -s -w : $_hg_global_opts \
538 '*:mercurial command:_hg_commands'
537 '*:mercurial command:_hg_commands'
539 }
538 }
540
539
541 _hg_cmd_identify() {
540 _hg_cmd_identify() {
542 _arguments -s -w : $_hg_global_opts \
541 _arguments -s -w : $_hg_global_opts \
543 '(--rev -r)'{-r+,--rev}'[identify the specified rev]:revision:_hg_tags' \
542 '(--rev -r)'{-r+,--rev}'[identify the specified rev]:revision:_hg_tags' \
544 '(--num -n)'{-n+,--num}'[show local revision number]' \
543 '(--num -n)'{-n+,--num}'[show local revision number]' \
545 '(--id -i)'{-i+,--id}'[show global revision id]' \
544 '(--id -i)'{-i+,--id}'[show global revision id]' \
546 '(--branch -b)'{-b+,--branch}'[show branch]' \
545 '(--branch -b)'{-b+,--branch}'[show branch]' \
547 '(--tags -t)'{-t+,--tags}'[show tags]'
546 '(--tags -t)'{-t+,--tags}'[show tags]'
548 }
547 }
549
548
550 _hg_cmd_import() {
549 _hg_cmd_import() {
551 _arguments -s -w : $_hg_global_opts \
550 _arguments -s -w : $_hg_global_opts \
552 '(--strip -p)'{-p+,--strip}'[directory strip option for patch (default: 1)]:count:' \
551 '(--strip -p)'{-p+,--strip}'[directory strip option for patch (default: 1)]:count:' \
553 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
552 '(--message -m)'{-m+,--message}'[use <text> as commit message]:text:' \
554 '(--force -f)'{-f,--force}'[skip check for outstanding uncommitted changes]' \
553 '(--force -f)'{-f,--force}'[skip check for outstanding uncommitted changes]' \
555 '*:patch:_files'
554 '*:patch:_files'
556 }
555 }
557
556
558 _hg_cmd_incoming() {
557 _hg_cmd_incoming() {
559 _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
558 _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
560 '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
559 '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
561 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
560 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
562 '(--patch -p)'{-p,--patch}'[show patch]' \
561 '(--patch -p)'{-p,--patch}'[show patch]' \
563 '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:_hg_tags' \
562 '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:_hg_tags' \
564 '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
563 '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
565 '--bundle[file to store the bundles into]:bundle file:_files' \
564 '--bundle[file to store the bundles into]:bundle file:_files' \
566 ':source:_hg_remote'
565 ':source:_hg_remote'
567 }
566 }
568
567
569 _hg_cmd_init() {
568 _hg_cmd_init() {
570 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
569 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
571 ':dir:_files -/'
570 ':dir:_files -/'
572 }
571 }
573
572
574 _hg_cmd_locate() {
573 _hg_cmd_locate() {
575 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
574 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
576 '(--rev -r)'{-r+,--rev}'[search repository as it stood at revision]:revision:_hg_tags' \
575 '(--rev -r)'{-r+,--rev}'[search repository as it stood at revision]:revision:_hg_tags' \
577 '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
576 '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
578 '(--fullpath -f)'{-f,--fullpath}'[print complete paths]' \
577 '(--fullpath -f)'{-f,--fullpath}'[print complete paths]' \
579 '*:search pattern:_hg_files'
578 '*:search pattern:_hg_files'
580 }
579 }
581
580
582 _hg_cmd_log() {
581 _hg_cmd_log() {
583 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_style_opts \
582 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_style_opts \
584 '(--follow --follow-first -f)'{-f,--follow}'[follow changeset or history]' \
583 '(--follow --follow-first -f)'{-f,--follow}'[follow changeset or history]' \
585 '(-f --follow)--follow-first[only follow the first parent of merge changesets]' \
584 '(-f --follow)--follow-first[only follow the first parent of merge changesets]' \
586 '(--copies -C)'{-C,--copies}'[show copied files]' \
585 '(--copies -C)'{-C,--copies}'[show copied files]' \
587 '(--keyword -k)'{-k+,--keyword}'[search for a keyword]:' \
586 '(--keyword -k)'{-k+,--keyword}'[search for a keyword]:' \
588 '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
587 '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
589 '*'{-r,--rev}'[show the specified revision or range]:revision:_hg_revrange' \
588 '*'{-r,--rev}'[show the specified revision or range]:revision:_hg_revrange' \
590 '(--no-merges -M)'{-M,--no-merges}'[do not show merges]' \
589 '(--no-merges -M)'{-M,--no-merges}'[do not show merges]' \
591 '(--only-merges -m)'{-m,--only-merges}'[show only merges]' \
590 '(--only-merges -m)'{-m,--only-merges}'[show only merges]' \
592 '(--patch -p)'{-p,--patch}'[show patch]' \
591 '(--patch -p)'{-p,--patch}'[show patch]' \
593 '(--prune -P)'{-P+,--prune}'[do not display revision or any of its ancestors]:revision:_hg_tags' \
592 '(--prune -P)'{-P+,--prune}'[do not display revision or any of its ancestors]:revision:_hg_tags' \
594 '*:files:_hg_files'
593 '*:files:_hg_files'
595 }
594 }
596
595
597 _hg_cmd_manifest() {
596 _hg_cmd_manifest() {
598 _arguments -s -w : $_hg_global_opts \
597 _arguments -s -w : $_hg_global_opts \
599 ':revision:_hg_tags'
598 ':revision:_hg_tags'
600 }
599 }
601
600
602 _hg_cmd_merge() {
601 _hg_cmd_merge() {
603 _arguments -s -w : $_hg_global_opts \
602 _arguments -s -w : $_hg_global_opts \
604 '(--force -f)'{-f,--force}'[force a merge with outstanding changes]' \
603 '(--force -f)'{-f,--force}'[force a merge with outstanding changes]' \
605 '(--rev -r 1)'{-r,--rev}'[revision to merge]:revision:_hg_mergerevs' \
604 '(--rev -r 1)'{-r,--rev}'[revision to merge]:revision:_hg_mergerevs' \
606 '(--preview -P)'{-P,--preview}'[review revisions to merge (no merge is performed)]' \
605 '(--preview -P)'{-P,--preview}'[review revisions to merge (no merge is performed)]' \
607 ':revision:_hg_mergerevs'
606 ':revision:_hg_mergerevs'
608 }
607 }
609
608
610 _hg_cmd_outgoing() {
609 _hg_cmd_outgoing() {
611 _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
610 _arguments -s -w : $_hg_global_opts $_hg_remote_opts $_hg_style_opts \
612 '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
611 '(--no-merges -M)'{-M,--no-merges}'[do not show merge revisions]' \
613 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
612 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
614 '(--patch -p)'{-p,--patch}'[show patch]' \
613 '(--patch -p)'{-p,--patch}'[show patch]' \
615 '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]' \
614 '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]' \
616 '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
615 '(--newest-first -n)'{-n,--newest-first}'[show newest record first]' \
617 ':destination:_hg_remote'
616 ':destination:_hg_remote'
618 }
617 }
619
618
620 _hg_cmd_parents() {
619 _hg_cmd_parents() {
621 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
620 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
622 '(--rev -r)'{-r+,--rev}'[show parents of the specified rev]:revision:_hg_tags' \
621 '(--rev -r)'{-r+,--rev}'[show parents of the specified rev]:revision:_hg_tags' \
623 ':last modified file:_hg_files'
622 ':last modified file:_hg_files'
624 }
623 }
625
624
626 _hg_cmd_paths() {
625 _hg_cmd_paths() {
627 _arguments -s -w : $_hg_global_opts \
626 _arguments -s -w : $_hg_global_opts \
628 ':path:_hg_paths'
627 ':path:_hg_paths'
629 }
628 }
630
629
631 _hg_cmd_pull() {
630 _hg_cmd_pull() {
632 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
631 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
633 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
632 '(--force -f)'{-f,--force}'[run even when the remote repository is unrelated]' \
634 '(--update -u)'{-u,--update}'[update to new tip if changesets were pulled]' \
633 '(--update -u)'{-u,--update}'[update to new tip if changesets were pulled]' \
635 '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:' \
634 '(--rev -r)'{-r+,--rev}'[a specific revision up to which you would like to pull]:revision:' \
636 ':source:_hg_remote'
635 ':source:_hg_remote'
637 }
636 }
638
637
639 _hg_cmd_push() {
638 _hg_cmd_push() {
640 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
639 _arguments -s -w : $_hg_global_opts $_hg_remote_opts \
641 '(--force -f)'{-f,--force}'[force push]' \
640 '(--force -f)'{-f,--force}'[force push]' \
642 '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]:revision:_hg_tags' \
641 '(--rev -r)'{-r+,--rev}'[a specific revision you would like to push]:revision:_hg_tags' \
643 ':destination:_hg_remote'
642 ':destination:_hg_remote'
644 }
643 }
645
644
646 _hg_cmd_remove() {
645 _hg_cmd_remove() {
647 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
646 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
648 '(--after -A)'{-A,--after}'[record remove that has already occurred]' \
647 '(--after -A)'{-A,--after}'[record remove that has already occurred]' \
649 '(--force -f)'{-f,--force}'[remove file even if modified]' \
648 '(--force -f)'{-f,--force}'[remove file even if modified]' \
650 '*:file:_hg_files'
649 '*:file:_hg_files'
651 }
650 }
652
651
653 _hg_cmd_rename() {
652 _hg_cmd_rename() {
654 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
653 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
655 '(--after -A)'{-A,--after}'[record a rename that has already occurred]' \
654 '(--after -A)'{-A,--after}'[record a rename that has already occurred]' \
656 '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
655 '(--force -f)'{-f,--force}'[forcibly copy over an existing managed file]' \
657 '*:file:_hg_files'
656 '*:file:_hg_files'
658 }
657 }
659
658
660 _hg_cmd_resolve() {
659 _hg_cmd_resolve() {
661 local context state line
660 local context state line
662 typeset -A opt_args
661 typeset -A opt_args
663
662
664 _arguments -s -w : $_hg_global_opts \
663 _arguments -s -w : $_hg_global_opts \
665 '(--list -l --mark -m --unmark -u)'{-l,--list}'[list state of files needing merge]:*:merged files:->resolve_files' \
664 '(--list -l --mark -m --unmark -u)'{-l,--list}'[list state of files needing merge]:*:merged files:->resolve_files' \
666 '(--mark -m --list -l --unmark -u)'{-m,--mark}'[mark files as resolved]:*:unresolved files:_hg_unresolved' \
665 '(--mark -m --list -l --unmark -u)'{-m,--mark}'[mark files as resolved]:*:unresolved files:_hg_unresolved' \
667 '(--unmark -u --list -l --mark -m)'{-u,--unmark}'[unmark files as resolved]:*:resolved files:_hg_resolved' \
666 '(--unmark -u --list -l --mark -m)'{-u,--unmark}'[unmark files as resolved]:*:resolved files:_hg_resolved' \
668 '*:file:_hg_unresolved'
667 '*:file:_hg_unresolved'
669
668
670 if [[ $state == 'resolve_files' ]]
669 if [[ $state == 'resolve_files' ]]
671 then
670 then
672 _alternative 'files:resolved files:_hg_resolved' \
671 _alternative 'files:resolved files:_hg_resolved' \
673 'files:unresolved files:_hg_unresolved'
672 'files:unresolved files:_hg_unresolved'
674 fi
673 fi
675 }
674 }
676
675
677 _hg_cmd_revert() {
676 _hg_cmd_revert() {
678 local context state line
677 local context state line
679 typeset -A opt_args
678 typeset -A opt_args
680
679
681 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
680 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_dryrun_opts \
682 '(--all -a :)'{-a,--all}'[revert all changes when no arguments given]' \
681 '(--all -a :)'{-a,--all}'[revert all changes when no arguments given]' \
683 '(--rev -r)'{-r+,--rev}'[revision to revert to]:revision:_hg_tags' \
682 '(--rev -r)'{-r+,--rev}'[revision to revert to]:revision:_hg_tags' \
684 '--no-backup[do not save backup copies of files]' \
683 '--no-backup[do not save backup copies of files]' \
685 '*:file:->diff_files'
684 '*:file:->diff_files'
686
685
687 if [[ $state == 'diff_files' ]]
686 if [[ $state == 'diff_files' ]]
688 then
687 then
689 if [[ -n $opt_args[-r] ]]
688 if [[ -n $opt_args[-r] ]]
690 then
689 then
691 _hg_files
690 _hg_files
692 else
691 else
693 typeset -a status_files
692 typeset -a status_files
694 _hg_status mard
693 _hg_status mard
695 _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files
694 _wanted files expl 'modified, added, removed or deleted file' _multi_parts / status_files
696 fi
695 fi
697 fi
696 fi
698 }
697 }
699
698
700 _hg_cmd_serve() {
699 _hg_cmd_serve() {
701 _arguments -s -w : $_hg_global_opts \
700 _arguments -s -w : $_hg_global_opts \
702 '(--accesslog -A)'{-A+,--accesslog}'[name of access log file]:log file:_files' \
701 '(--accesslog -A)'{-A+,--accesslog}'[name of access log file]:log file:_files' \
703 '(--errorlog -E)'{-E+,--errorlog}'[name of error log file]:log file:_files' \
702 '(--errorlog -E)'{-E+,--errorlog}'[name of error log file]:log file:_files' \
704 '(--daemon -d)'{-d,--daemon}'[run server in background]' \
703 '(--daemon -d)'{-d,--daemon}'[run server in background]' \
705 '(--port -p)'{-p+,--port}'[listen port]:listen port:' \
704 '(--port -p)'{-p+,--port}'[listen port]:listen port:' \
706 '(--address -a)'{-a+,--address}'[interface address]:interface address:' \
705 '(--address -a)'{-a+,--address}'[interface address]:interface address:' \
707 '(--name -n)'{-n+,--name}'[name to show in web pages]:repository name:' \
706 '(--name -n)'{-n+,--name}'[name to show in web pages]:repository name:' \
708 '(--templates -t)'{-t,--templates}'[web template directory]:template dir:_files -/' \
707 '(--templates -t)'{-t,--templates}'[web template directory]:template dir:_files -/' \
709 '--style[web template style]:style' \
708 '--style[web template style]:style' \
710 '--stdio[for remote clients]' \
709 '--stdio[for remote clients]' \
711 '(--ipv6 -6)'{-6,--ipv6}'[use IPv6 in addition to IPv4]'
710 '(--ipv6 -6)'{-6,--ipv6}'[use IPv6 in addition to IPv4]'
712 }
711 }
713
712
714 _hg_cmd_showconfig() {
713 _hg_cmd_showconfig() {
715 _arguments -s -w : $_hg_global_opts \
714 _arguments -s -w : $_hg_global_opts \
716 '(--untrusted -u)'{-u+,--untrusted}'[show untrusted configuration options]' \
715 '(--untrusted -u)'{-u+,--untrusted}'[show untrusted configuration options]' \
717 ':config item:_hg_config'
716 ':config item:_hg_config'
718 }
717 }
719
718
720 _hg_cmd_status() {
719 _hg_cmd_status() {
721 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
720 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
722 '(--all -A)'{-A,--all}'[show status of all files]' \
721 '(--all -A)'{-A,--all}'[show status of all files]' \
723 '(--modified -m)'{-m,--modified}'[show only modified files]' \
722 '(--modified -m)'{-m,--modified}'[show only modified files]' \
724 '(--added -a)'{-a,--added}'[show only added files]' \
723 '(--added -a)'{-a,--added}'[show only added files]' \
725 '(--removed -r)'{-r,--removed}'[show only removed files]' \
724 '(--removed -r)'{-r,--removed}'[show only removed files]' \
726 '(--deleted -d)'{-d,--deleted}'[show only deleted (but tracked) files]' \
725 '(--deleted -d)'{-d,--deleted}'[show only deleted (but tracked) files]' \
727 '(--clean -c)'{-c,--clean}'[show only files without changes]' \
726 '(--clean -c)'{-c,--clean}'[show only files without changes]' \
728 '(--unknown -u)'{-u,--unknown}'[show only unknown files]' \
727 '(--unknown -u)'{-u,--unknown}'[show only unknown files]' \
729 '(--ignored -i)'{-i,--ignored}'[show ignored files]' \
728 '(--ignored -i)'{-i,--ignored}'[show ignored files]' \
730 '(--no-status -n)'{-n,--no-status}'[hide status prefix]' \
729 '(--no-status -n)'{-n,--no-status}'[hide status prefix]' \
731 '(--copies -C)'{-C,--copies}'[show source of copied files]' \
730 '(--copies -C)'{-C,--copies}'[show source of copied files]' \
732 '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
731 '(--print0 -0)'{-0,--print0}'[end filenames with NUL, for use with xargs]' \
733 '--rev[show difference from revision]:revision:_hg_tags' \
732 '--rev[show difference from revision]:revision:_hg_tags' \
734 '*:files:_files'
733 '*:files:_files'
735 }
734 }
736
735
737 _hg_cmd_summary() {
736 _hg_cmd_summary() {
738 _arguments -s -w : $_hg_global_opts \
737 _arguments -s -w : $_hg_global_opts \
739 '--remote[check for push and pull]'
738 '--remote[check for push and pull]'
740 }
739 }
741
740
742 _hg_cmd_tag() {
741 _hg_cmd_tag() {
743 _arguments -s -w : $_hg_global_opts \
742 _arguments -s -w : $_hg_global_opts \
744 '(--local -l)'{-l,--local}'[make the tag local]' \
743 '(--local -l)'{-l,--local}'[make the tag local]' \
745 '(--message -m)'{-m+,--message}'[message for tag commit log entry]:message:' \
744 '(--message -m)'{-m+,--message}'[message for tag commit log entry]:message:' \
746 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
745 '(--date -d)'{-d+,--date}'[record datecode as commit date]:date code:' \
747 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
746 '(--user -u)'{-u+,--user}'[record user as commiter]:user:' \
748 '(--rev -r)'{-r+,--rev}'[revision to tag]:revision:_hg_tags' \
747 '(--rev -r)'{-r+,--rev}'[revision to tag]:revision:_hg_tags' \
749 ':tag name:'
748 ':tag name:'
750 }
749 }
751
750
752 _hg_cmd_tip() {
751 _hg_cmd_tip() {
753 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
752 _arguments -s -w : $_hg_global_opts $_hg_style_opts \
754 '(--patch -p)'{-p,--patch}'[show patch]'
753 '(--patch -p)'{-p,--patch}'[show patch]'
755 }
754 }
756
755
757 _hg_cmd_unbundle() {
756 _hg_cmd_unbundle() {
758 _arguments -s -w : $_hg_global_opts \
757 _arguments -s -w : $_hg_global_opts \
759 '(--update -u)'{-u,--update}'[update to new tip if changesets were unbundled]' \
758 '(--update -u)'{-u,--update}'[update to new tip if changesets were unbundled]' \
760 ':files:_files'
759 ':files:_files'
761 }
760 }
762
761
763 _hg_cmd_update() {
762 _hg_cmd_update() {
764 _arguments -s -w : $_hg_global_opts \
763 _arguments -s -w : $_hg_global_opts \
765 '(--clean -C)'{-C,--clean}'[overwrite locally modified files]' \
764 '(--clean -C)'{-C,--clean}'[overwrite locally modified files]' \
766 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
765 '(--rev -r)'{-r+,--rev}'[revision]:revision:_hg_tags' \
767 ':revision:_hg_tags'
766 ':revision:_hg_tags'
768 }
767 }
769
768
770 # HGK
769 # HGK
771 _hg_cmd_view() {
770 _hg_cmd_view() {
772 _arguments -s -w : $_hg_global_opts \
771 _arguments -s -w : $_hg_global_opts \
773 '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
772 '(--limit -l)'{-l+,--limit}'[limit number of changes displayed]:' \
774 ':revision range:_hg_tags'
773 ':revision range:_hg_tags'
775 }
774 }
776
775
777 # MQ
776 # MQ
778 _hg_qseries() {
777 _hg_qseries() {
779 typeset -a patches
778 typeset -a patches
780 patches=(${(f)"$(_hg_cmd qseries)"})
779 patches=(${(f)"$(_hg_cmd qseries)"})
781 (( $#patches )) && _describe -t hg-patches 'patches' patches
780 (( $#patches )) && _describe -t hg-patches 'patches' patches
782 }
781 }
783
782
784 _hg_qapplied() {
783 _hg_qapplied() {
785 typeset -a patches
784 typeset -a patches
786 patches=(${(f)"$(_hg_cmd qapplied)"})
785 patches=(${(f)"$(_hg_cmd qapplied)"})
787 if (( $#patches ))
786 if (( $#patches ))
788 then
787 then
789 patches+=(qbase qtip)
788 patches+=(qbase qtip)
790 _describe -t hg-applied-patches 'applied patches' patches
789 _describe -t hg-applied-patches 'applied patches' patches
791 fi
790 fi
792 }
791 }
793
792
794 _hg_qunapplied() {
793 _hg_qunapplied() {
795 typeset -a patches
794 typeset -a patches
796 patches=(${(f)"$(_hg_cmd qunapplied)"})
795 patches=(${(f)"$(_hg_cmd qunapplied)"})
797 (( $#patches )) && _describe -t hg-unapplied-patches 'unapplied patches' patches
796 (( $#patches )) && _describe -t hg-unapplied-patches 'unapplied patches' patches
798 }
797 }
799
798
800 # unapplied, including guarded patches
799 # unapplied, including guarded patches
801 _hg_qdeletable() {
800 _hg_qdeletable() {
802 typeset -a unapplied
801 typeset -a unapplied
803 unapplied=(${(f)"$(_hg_cmd qseries)"})
802 unapplied=(${(f)"$(_hg_cmd qseries)"})
804 for p in $(_hg_cmd qapplied)
803 for p in $(_hg_cmd qapplied)
805 do
804 do
806 unapplied=(${unapplied:#$p})
805 unapplied=(${unapplied:#$p})
807 done
806 done
808
807
809 (( $#unapplied )) && _describe -t hg-allunapplied-patches 'all unapplied patches' unapplied
808 (( $#unapplied )) && _describe -t hg-allunapplied-patches 'all unapplied patches' unapplied
810 }
809 }
811
810
812 _hg_qguards() {
811 _hg_qguards() {
813 typeset -a guards
812 typeset -a guards
814 local guard
813 local guard
815 compset -P "+|-"
814 compset -P "+|-"
816 _hg_cmd qselect -s | while read guard
815 _hg_cmd qselect -s | while read guard
817 do
816 do
818 guards+=(${guard#(+|-)})
817 guards+=(${guard#(+|-)})
819 done
818 done
820 (( $#guards )) && _describe -t hg-guards 'guards' guards
819 (( $#guards )) && _describe -t hg-guards 'guards' guards
821 }
820 }
822
821
823 _hg_qseries_opts=(
822 _hg_qseries_opts=(
824 '(--summary -s)'{-s,--summary}'[print first line of patch header]')
823 '(--summary -s)'{-s,--summary}'[print first line of patch header]')
825
824
826 _hg_cmd_qapplied() {
825 _hg_cmd_qapplied() {
827 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
826 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
828 }
827 }
829
828
830 _hg_cmd_qdelete() {
829 _hg_cmd_qdelete() {
831 _arguments -s -w : $_hg_global_opts \
830 _arguments -s -w : $_hg_global_opts \
832 '(--keep -k)'{-k,--keep}'[keep patch file]' \
831 '(--keep -k)'{-k,--keep}'[keep patch file]' \
833 '*'{-r+,--rev}'[stop managing a revision]:applied patch:_hg_revrange' \
832 '*'{-r+,--rev}'[stop managing a revision]:applied patch:_hg_revrange' \
834 '*:unapplied patch:_hg_qdeletable'
833 '*:unapplied patch:_hg_qdeletable'
835 }
834 }
836
835
837 _hg_cmd_qdiff() {
836 _hg_cmd_qdiff() {
838 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
837 _arguments -s -w : $_hg_global_opts $_hg_pat_opts \
839 '*:pattern:_hg_files'
838 '*:pattern:_hg_files'
840 }
839 }
841
840
842 _hg_cmd_qfold() {
841 _hg_cmd_qfold() {
843 _arguments -s -w : $_hg_global_opts $_h_commit_opts \
842 _arguments -s -w : $_hg_global_opts $_h_commit_opts \
844 '(--keep,-k)'{-k,--keep}'[keep folded patch files]' \
843 '(--keep,-k)'{-k,--keep}'[keep folded patch files]' \
845 '*:unapplied patch:_hg_qunapplied'
844 '*:unapplied patch:_hg_qunapplied'
846 }
845 }
847
846
848 _hg_cmd_qgoto() {
847 _hg_cmd_qgoto() {
849 _arguments -s -w : $_hg_global_opts \
848 _arguments -s -w : $_hg_global_opts \
850 '(--force -f)'{-f,--force}'[overwrite any local changes]' \
849 '(--force -f)'{-f,--force}'[overwrite any local changes]' \
851 ':patch:_hg_qseries'
850 ':patch:_hg_qseries'
852 }
851 }
853
852
854 _hg_cmd_qguard() {
853 _hg_cmd_qguard() {
855 _arguments -s -w : $_hg_global_opts \
854 _arguments -s -w : $_hg_global_opts \
856 '(--list -l)'{-l,--list}'[list all patches and guards]' \
855 '(--list -l)'{-l,--list}'[list all patches and guards]' \
857 '(--none -n)'{-n,--none}'[drop all guards]' \
856 '(--none -n)'{-n,--none}'[drop all guards]' \
858 ':patch:_hg_qseries' \
857 ':patch:_hg_qseries' \
859 '*:guards:_hg_qguards'
858 '*:guards:_hg_qguards'
860 }
859 }
861
860
862 _hg_cmd_qheader() {
861 _hg_cmd_qheader() {
863 _arguments -s -w : $_hg_global_opts \
862 _arguments -s -w : $_hg_global_opts \
864 ':patch:_hg_qseries'
863 ':patch:_hg_qseries'
865 }
864 }
866
865
867 _hg_cmd_qimport() {
866 _hg_cmd_qimport() {
868 _arguments -s -w : $_hg_global_opts \
867 _arguments -s -w : $_hg_global_opts \
869 '(--existing -e)'{-e,--existing}'[import file in patch dir]' \
868 '(--existing -e)'{-e,--existing}'[import file in patch dir]' \
870 '(--name -n 2)'{-n+,--name}'[patch file name]:name:' \
869 '(--name -n 2)'{-n+,--name}'[patch file name]:name:' \
871 '(--force -f)'{-f,--force}'[overwrite existing files]' \
870 '(--force -f)'{-f,--force}'[overwrite existing files]' \
872 '*'{-r+,--rev}'[place existing revisions under mq control]:revision:_hg_revrange' \
871 '*'{-r+,--rev}'[place existing revisions under mq control]:revision:_hg_revrange' \
873 '*:patch:_files'
872 '*:patch:_files'
874 }
873 }
875
874
876 _hg_cmd_qnew() {
875 _hg_cmd_qnew() {
877 _arguments -s -w : $_hg_global_opts $_hg_commit_opts \
876 _arguments -s -w : $_hg_global_opts $_hg_commit_opts \
878 '(--force -f)'{-f,--force}'[import uncommitted changes into patch]' \
877 '(--force -f)'{-f,--force}'[import uncommitted changes into patch]' \
879 ':patch:'
878 ':patch:'
880 }
879 }
881
880
882 _hg_cmd_qnext() {
881 _hg_cmd_qnext() {
883 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
882 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
884 }
883 }
885
884
886 _hg_cmd_qpop() {
885 _hg_cmd_qpop() {
887 _arguments -s -w : $_hg_global_opts \
886 _arguments -s -w : $_hg_global_opts \
888 '(--all -a :)'{-a,--all}'[pop all patches]' \
887 '(--all -a :)'{-a,--all}'[pop all patches]' \
889 '(--name -n)'{-n+,--name}'[queue name to pop]:' \
888 '(--name -n)'{-n+,--name}'[queue name to pop]:' \
890 '(--force -f)'{-f,--force}'[forget any local changes]' \
889 '(--force -f)'{-f,--force}'[forget any local changes]' \
891 ':patch:_hg_qapplied'
890 ':patch:_hg_qapplied'
892 }
891 }
893
892
894 _hg_cmd_qprev() {
893 _hg_cmd_qprev() {
895 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
894 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
896 }
895 }
897
896
898 _hg_cmd_qpush() {
897 _hg_cmd_qpush() {
899 _arguments -s -w : $_hg_global_opts \
898 _arguments -s -w : $_hg_global_opts \
900 '(--all -a :)'{-a,--all}'[apply all patches]' \
899 '(--all -a :)'{-a,--all}'[apply all patches]' \
901 '(--list -l)'{-l,--list}'[list patch name in commit text]' \
900 '(--list -l)'{-l,--list}'[list patch name in commit text]' \
902 '(--merge -m)'{-m+,--merge}'[merge from another queue]:' \
901 '(--merge -m)'{-m+,--merge}'[merge from another queue]:' \
903 '(--name -n)'{-n+,--name}'[merge queue name]:' \
902 '(--name -n)'{-n+,--name}'[merge queue name]:' \
904 '(--force -f)'{-f,--force}'[apply if the patch has rejects]' \
903 '(--force -f)'{-f,--force}'[apply if the patch has rejects]' \
905 ':patch:_hg_qunapplied'
904 ':patch:_hg_qunapplied'
906 }
905 }
907
906
908 _hg_cmd_qrefresh() {
907 _hg_cmd_qrefresh() {
909 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_commit_opts \
908 _arguments -s -w : $_hg_global_opts $_hg_pat_opts $_hg_commit_opts \
910 '(--git -g)'{-g,--git}'[use git extended diff format]' \
909 '(--git -g)'{-g,--git}'[use git extended diff format]' \
911 '(--short -s)'{-s,--short}'[short refresh]' \
910 '(--short -s)'{-s,--short}'[short refresh]' \
912 '*:files:_hg_files'
911 '*:files:_hg_files'
913 }
912 }
914
913
915 _hg_cmd_qrename() {
914 _hg_cmd_qrename() {
916 _arguments -s -w : $_hg_global_opts \
915 _arguments -s -w : $_hg_global_opts \
917 ':patch:_hg_qseries' \
916 ':patch:_hg_qseries' \
918 ':destination:'
917 ':destination:'
919 }
918 }
920
919
921 _hg_cmd_qselect() {
920 _hg_cmd_qselect() {
922 _arguments -s -w : $_hg_global_opts \
921 _arguments -s -w : $_hg_global_opts \
923 '(--none -n :)'{-n,--none}'[disable all guards]' \
922 '(--none -n :)'{-n,--none}'[disable all guards]' \
924 '(--series -s :)'{-s,--series}'[list all guards in series file]' \
923 '(--series -s :)'{-s,--series}'[list all guards in series file]' \
925 '--pop[pop to before first guarded applied patch]' \
924 '--pop[pop to before first guarded applied patch]' \
926 '--reapply[pop and reapply patches]' \
925 '--reapply[pop and reapply patches]' \
927 '*:guards:_hg_qguards'
926 '*:guards:_hg_qguards'
928 }
927 }
929
928
930 _hg_cmd_qseries() {
929 _hg_cmd_qseries() {
931 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts \
930 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts \
932 '(--missing -m)'{-m,--missing}'[print patches not in series]'
931 '(--missing -m)'{-m,--missing}'[print patches not in series]'
933 }
932 }
934
933
935 _hg_cmd_qunapplied() {
934 _hg_cmd_qunapplied() {
936 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
935 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
937 }
936 }
938
937
939 _hg_cmd_qtop() {
938 _hg_cmd_qtop() {
940 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
939 _arguments -s -w : $_hg_global_opts $_hg_qseries_opts
941 }
940 }
942
941
943 _hg_cmd_strip() {
942 _hg_cmd_strip() {
944 _arguments -s -w : $_hg_global_opts \
943 _arguments -s -w : $_hg_global_opts \
945 '(--force -f)'{-f,--force}'[force multi-head removal]' \
944 '(--force -f)'{-f,--force}'[force multi-head removal]' \
946 '(--backup -b)'{-b,--backup}'[bundle unrelated changesets]' \
945 '(--backup -b)'{-b,--backup}'[bundle unrelated changesets]' \
947 '(--nobackup -n)'{-n,--nobackup}'[no backups]' \
946 '(--nobackup -n)'{-n,--nobackup}'[no backups]' \
948 ':revision:_hg_tags'
947 ':revision:_hg_tags'
949 }
948 }
950
949
951 _hg "$@"
950 _hg "$@"
General Comments 0
You need to be logged in to leave comments. Login now