comparison .zfun/_hg @ 55:846d556d9619

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