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