Improved variable naming for refresh
[stgit.git] / completion / stgit.zsh
blob89b9e761c505fd21e9ddb56cf88c5c9cf30551e8
1 #compdef stg
3 # This script implements zsh completions for StGit (stg).
5 # To use these completions, copy to a directory in $fpath as _stgit.
6 # For example:
8 # $ mkdir ~/.zsh.d
9 # $ cp completion/stgit.zsh ~/.zsh.d/_stgit
10 # $ $EDITOR ~/.zshrc
12 # fpath=("$HOME/.zsh.d" $fpath)
13 # autoload -U compinit
16 _stg-branch() {
17 __stg_add_args_help
18 subcmd_args+=(
19 - group-list
20 '--list[list branches]'
21 - group-switch
22 '--merge[merge worktree changes into other branch]'
23 ':branch:__stg_branch_stgit'
24 - group-create
25 '--create[create and switch to new branch]'
26 ':new-branch:'
27 ':committish:'
28 - group-clone
29 '--clone[clone current branch to new branch]'
30 ':new-branch:'
31 - group-rename
32 '(-r --rename)'{-r,--rename}'[rename existing branch]'
33 ':branch:__stg_branch_stgit'
34 ':new-branch:'
35 - group-protect
36 '(-p --protect)'{-p,--protect}'[prevent stg from modifying branch]'
37 ':branch:__stg_branch_stgit'
38 - group-unprotect
39 '(-u --unprotect)'{-u,--unprotect}'[allow stg to modify branch]'
40 ':branch:__stg_branch_stgit'
41 - group-delete
42 '--delete[delete branch]'
43 '--force[force delete when series is non-empty]'
44 ':branch:__stg_branch_stgit'
45 - group-cleanup
46 '--cleanup[cleanup stg metadata for branch]'
47 '--force[force cleanup when series is non-empty]'
48 ':branch:__stg_branch_stgit'
49 - group-description
50 '(-d --description)'{-d,--description}'[set branch description]:description'
51 ':branch:__stg_branch_stgit'
53 _arguments -s -S $subcmd_args
56 _stg-clean() {
57 __stg_add_args_help
58 subcmd_args+=(
59 '(-a --applied)'{-a,--applied}'[delete empty applied patches]'
60 '(-u --unapplied)'{-u,--unapplied}'[delete empty unapplied patches]'
62 _arguments -s -S $subcmd_args
65 _stg-clone() {
66 __stg_add_args_help
67 subcmd_args+=(
68 ':repository:'
69 ': :_directories'
71 _arguments -s $subcmd_args
74 _stg-commit() {
75 __stg_add_args_help
76 subcmd_args+=(
77 - group-all
78 '(-a --all)'{-a,--all}'[commit all unapplied patches]'
79 - group-number
80 '(-n --number)'{-n+,--number=}'[commit specified number of patches]:number'
81 - group-patches
82 '*:applied patches:__stg_patches_applied'
84 _arguments -s -S $subcmd_args
87 _stg-delete() {
88 __stg_add_args_help
89 __stg_add_args_branch
90 subcmd_args+=(
91 '--spill[spill patch contents to worktree and index]'
92 - group-top
93 '(-t --top)'{-t,--top}'[delete top patch]'
94 - group-patchnames
95 '*:patches:__stg_patches_all'
97 _arguments -s -S $subcmd_args
100 _stg-diff() {
101 __stg_add_args_help
102 __stg_add_args_diffopts
103 subcmd_args+=(
104 '(-r --range)'{-r,--range=}'[show diff between revisions]: :__stg_patches_all'
105 '(-s --stat)'{-s,--stat}'[show stat instead of diff]'
106 '*:files:__stg_files_dirty'
108 _arguments -s -S $subcmd_args
111 _stg-edit() {
112 __stg_add_args_help
113 __stg_add_args_author
114 __stg_add_args_diffopts
115 __stg_add_args_edit
116 __stg_add_args_hook
117 __stg_add_args_savetemplate
118 __stg_add_args_sign
119 subcmd_args+=(
120 '(-d --diff)'{-d,--diff}'[edit patch diff]'
121 '(-t --set-tree)'{-t,--set-tree=}'[set git tree of patch]:treeish'
122 ':patch:__stg_patches_all'
124 __stg_add_args_message
125 _arguments -s -S $subcmd_args
128 _stg-export() {
129 __stg_add_args_help
130 __stg_add_args_branch
131 __stg_add_args_diffopts
132 subcmd_args+=(
133 '(-d --dir)'{-d,--dir}'[export patches to directory]: :_directories'
134 '(-n --numbered)'{-n,--numbered}'[prefix patch names with order numbers]'
135 '(-s --stdout)'{-s,--stdout}'[dump patches to standard output]'
136 '(-t --template)'{-t,--template=}'[use template file]: :_files'
137 '*:patches:__stg_patches_unhidden'
138 + '(suffix)'
139 '(-e --extension)'{-e,--extension=}'[extension to append to patch names]:extension'
140 '(-p --patch)'{-p,--patch}'[append .patch to patch names]'
142 _arguments -s -S $subcmd_args
145 _stg-files() {
146 __stg_add_args_help
147 __stg_add_args_diffopts
148 subcmd_args+=(
149 '--bare[bare file names]'
150 '(-s --stat)'{-s,--stat}'[show diff stat]'
151 ':patches:__stg_patches_all'
153 _arguments -s -S $subcmd_args
156 _stg-float() {
157 __stg_add_args_help
158 __stg_add_args_keep
159 subcmd_args+=(
160 '(-s --series)'{-s,--series=}'[arrange according to series file]: :_files'
161 ':patches:__stg_patches_all'
163 _arguments -s -S $subcmd_args
166 _stg-fold() {
167 __stg_add_args_help
168 subcmd_args+=(
169 '(-b --base)'{-b,--base=}'[apply on base commit instead of HEAD]:commit'
170 '(-p --strip)'{-p+,--strip=}'[remove N leading directories from diff paths]:num'
171 '--reject[leave rejected hunks in .rej files]'
172 ':file:_files'
174 _arguments -s -S $subcmd_args
177 _stg-goto() {
178 __stg_add_args_help
179 __stg_add_args_keep
180 __stg_add_args_merged
181 subcmd_args+=(
182 ':patches:__stg_patches_all'
184 _arguments -s -S $subcmd_args
187 _stg-help() {
188 _arguments -s ':commands:__stg_subcommands'
191 _stg-hide() {
192 __stg_add_args_help
193 __stg_add_args_branch
194 subcmd_args+=(
195 ':patches:__stg_patches_unhidden'
197 _arguments -s -S $subcmd_args
200 _stg-id() {
201 __stg_add_args_help
202 subcmd_args+=(
203 ':references:__stg_patches_all'
205 _arguments -s -S $subcmd_args
208 _stg-import() {
209 __stg_add_args_help
210 __stg_add_args_author
211 __stg_add_args_edit
212 __stg_add_args_sign
213 subcmd_args+=(
214 '(-n --name)'{-n,--name}'[name for imported patch]'
215 '(-p --strip)'{-p+,--strip=}'[remove N leading directories from diff paths]:num'
216 '(-t --stripname)'{-t,--stripname}'[strip number and extension from patch name]'
217 '(-i --ignore)'{-i,--ignore}'[ingore applied patches in series]'
218 '--replace[replace unapplied patches in series]'
219 '--reject[leave rejected hunks in .rej files]'
220 '--keep-cr[do not remove CR from email lines ending with CRLF]'
221 '(-d --showdiff)'{-d,--showdiff}'[show patch content in editor buffer]'
222 ':file:_files'
223 + '(source)'
224 '(-m --mail)'{-m,--mail}'[import from standard email file]'
225 '(-M --mbox)'{-M,--mbox}'[import from mbox file]'
226 '(-s --series)'{-s,--series}'[import from series file]'
227 '(-u --url)'{-u,--url}'[import patch from URL]'
229 _arguments -s -S $subcmd_args
232 _stg-init() {
233 __stg_add_args_help
234 _arguments -s $subcmd_args
237 _stg-log() {
238 __stg_add_args_help
239 __stg_add_args_branch
240 subcmd_args+=(
241 '--clear[clear log history]'
242 '(-d --diff)'{-d,--diff}'[show refresh diffs]'
243 '(-f --full)'{-f,--full}'[show full commit ids]'
244 '(-g --graphical)'{-g,--graphical}'[show log in gitk]'
245 '(-n --number)'{-n+,--number=}'[limit to number of commits]'
246 '*:patches:__stg_patches_all'
248 _arguments -s -S $subcmd_args
251 _stg-mail() {
252 __stg_add_args_help
253 __stg_add_args_branch
254 __stg_add_args_diffopts
255 subcmd_args+=(
256 '--to=[add address to To: list]:address'
257 '--cc=[add address to Cc: list]:address'
258 '--bcc=[add address to Bcc: list]:address'
259 '--auto[automatically cc patch signers]'
260 '--no-thread[do not send subsequent messages as replies]'
261 '--unrelated[send patches without sequence numbers]'
262 '(-v --version)'{-v,--version=}'[add version to subject prefix]:version'
263 '--prefix=[add prefix to subject]:prefix'
264 '(-c --cover)'{-c,--cover=}'[cover message file]: :_files'
265 '(-e --edit-cover)'{-e,--edit-cover}'[edit cover message before sending]'
266 '(-E --edit-patches)'{-E,--edit-patches}'[edit patches before sending]'
267 '(-s --sleep)'{-s,--sleep=}'[seconds to sleep between sending emails]:seconds'
268 '--in-reply-to=[reply reference id]:refid'
269 '--domain=[domain to use for message ID]:domain'
270 '(-u --user)'{-u,--user=}'[username for SMTP authentication]:user'
271 '(-p --password)'{-p,--password=}'[password for SMTP authentication]:password'
272 '(-T --smtp-tls)'{-t,--smtp-tls}'[use TLS for SMTP authentication]'
273 + '(send-method)'
274 '--git[use `git send-email`]'
275 '(-m --mbox)'{-m,--mbox}'[generate mbox file instead of sending]'
276 '--smtp-server=[server or command for sending email]'
277 + '(attachment)'
278 '--attach[send patch as attachment]'
279 '--attach-inline[send patch as inline attachment]'
280 '(-t --template)'{-t,--template=}'[message template file]: :_files'
281 + '(patches)'
282 '(-a --all)'{-a,--all}'[email all applied patches]'
283 '*:patches:__stg_patches_all'
285 _arguments -s -S $subcmd_args
288 _stg-new() {
289 __stg_add_args_help
290 __stg_add_args_author
291 __stg_add_args_sign
292 __stg_add_args_hook
293 __stg_add_args_savetemplate
294 subcmd_args+=(
295 ':name:'
297 __stg_add_args_message
298 _arguments -s -S $subcmd_args
301 _stg-next() {
302 __stg_add_args_help
303 __stg_add_args_branch
304 _arguments -s -S $subcmd_args
307 _stg-patches() {
308 __stg_add_args_help
309 __stg_add_args_branch
310 __stg_add_args_diffopts
311 subcmd_args+=(
312 '(-d --diff)'{-d,--diff}'[show diffs of given files]'
313 '*:files:__stg_files_known'
315 _arguments -s -S $subcmd_args
318 _stg-pick() {
319 # TODO: consider --ref-branch for patches completion
320 # TODO: complete --parent commit id
321 __stg_add_args_help
322 subcmd_args+=(
323 '(-n --name)'{-n,--name=}'[name for picked patch]:name'
324 '(-B --ref-branch)'{-B,--ref-branch=}'[pick patches from branch]: :__stg_branch_stgit'
325 '(-r --revert)'{-r,--revert}'[revert given commit object]'
326 '(-p --parent=)'{-p,--parent}'[use commit id as parent]:commit'
327 '(-x --expose)'{-x,--expose}'[append imported commit id to patch log]'
328 '--unapplied[keep patch unapplied]'
329 '*'{-f,--file=}'[only fold given file]: :_files'
330 '*:patches:__stg_patches_all'
331 + '(mode)'
332 '--fold[fold the commit into current patch]'
333 '--update[fold limited to current patch files]'
335 _arguments -s -S $subcmd_args
338 _stg-pop() {
339 __stg_add_args_help
340 __stg_add_args_keep
341 subcmd_args+=(
342 '(-s --spill)'{-s,--spill}'[pop a patch keeping its modifications in the tree]'
343 - group-number
344 '(-n --number)'{-n+,--number=}'[push specified number of patches]:number'
345 - group-all
346 '(-a --all)'{-a,--all}'[push all unapplied patches]'
347 - group-patches
348 '*:applied patches:__stg_patches_applied'
350 _arguments -s -S $subcmd_args
353 _stg-prev() {
354 __stg_add_args_help
355 __stg_add_args_branch
356 _arguments -s -S $subcmd_args
359 _stg-pull() {
360 __stg_add_args_help
361 __stg_add_args_merged
362 subcmd_args+=(
363 '(-n --nopush)'{-n,--nopush}'[do not push patches after rebasing]'
364 ':repository:__stg_remotes'
366 _arguments -s -S $subcmd_args
369 _stg-push() {
370 __stg_add_args_help
371 __stg_add_args_keep
372 __stg_add_args_merged
373 subcmd_args+=(
374 '--reverse[push patches in reverse order]'
375 '--set-tree[push patch with the original tree]'
376 - group-all
377 '(-a --all)'{-a,--all}'[push all unapplied patches]'
378 - group-number
379 '(-n --number)'{-n+,--number=}'[push specified number of patches]:number'
380 - group-patches
381 '*:unapplied patches:__stg_patches_unapplied'
383 _arguments -s -S $subcmd_args
386 _stg-rebase() {
387 __stg_add_args_help
388 __stg_add_args_merged
389 subcmd_args+=(
390 '(-n --nopush)'{-n,--nopush}'[do not push patches after rebasing]'
391 ':new-base-id:'
393 _arguments -s -S $subcmd_args
396 _stg-redo() {
397 __stg_add_args_help
398 subcmd_args+=(
399 '--hard[discard changes in index/worktree]'
400 '(-n --number)'{-n+,--number=}'[number of undos to redo]:number'
402 _arguments -s -S $subcmd_args
405 _stg-refresh() {
406 __stg_add_args_help
407 __stg_add_args_author
408 __stg_add_args_edit
409 __stg_add_args_hook
410 __stg_add_args_sign
411 subcmd_args+=(
412 '(-a --annotate)'{-a,--annotate=}'[annotate patch log entry]:note'
413 '(-F --force)'{-F,--force}'[force refresh even if index is dirty]'
414 '(-i --index)'{-i,--index}'[refresh from index instead of worktree]'
415 '(-p --patch)'{-p,--patch=}'[refresh patch other than top patch]: :__stg_patches_applied'
416 '--spill[Spill patch contents to worktree and index, and erase patch content]'
417 + '(update-files)'
418 '(-u --update)'{-u,--update}'[only update current patch files]'
419 '*:files:__stg_files_dirty'
420 + '(submodules)'
421 '(-s --submodules)'{-s,--submodules}'[include submodules in refresh]'
422 '--no-submodules[exclude submodules from refresh]'
424 __stg_add_args_message
425 _arguments -s -S $subcmd_args
428 _stg-rename() {
429 __stg_add_args_help
430 __stg_add_args_branch
431 subcmd_args+=(
432 ':old-patch:__stg_patches_all'
434 _arguments -s -S $subcmd_args
437 _stg-repair() {
438 __stg_add_args_help
439 _arguments -s $subcmd_args
442 _stg-reset() {
443 __stg_add_args_help
444 subcmd_args+=(
445 '--hard[discard changes in index/worktree]'
446 ':state:'
447 '*:patches:__stg_patches_all'
449 _arguments -s -S $subcmd_args
452 _stg-series() {
453 __stg_add_args_help
454 __stg_add_args_branch
455 subcmd_args+=(
456 '--author[show the author name for each patch]'
457 '(-c --count)'{-c,--count}'[print number of patches]'
458 '(-d --description)'{-d,--description}'[show short descriptions]'
459 '(-e --empty)'{-e,--empty}'[identify empty patches]'
460 '(-m --missing)'{-m,--missing=}'[show patches from branch missing in current]: :__stg_branch_stgit'
461 '--noprefix[do not show the patch status prefix]'
462 '(-s --short)'{-s,--short}'[list just patches around the topmost patch]'
463 '--showbranch[show branch name of listed patches]'
464 - group-ahu
465 '(-A --applied)'{-A,--applied}'[show applied patches]'
466 '(-H --hidden)'{-H,--hidden}'[show hidden patches]'
467 '(-U --unapplied)'{-U,--unapplied}'[show unapplied patches]'
468 - group-all
469 '(-a --all)'{-a,--all}'[show all patches including hidden]'
470 - group-patches
471 ':patches:__stg_patches_all'
473 _arguments -s -S $subcmd_args
476 _stg-show() {
477 __stg_add_args_help
478 __stg_add_args_branch
479 __stg_add_args_diffopts
480 subcmd_args+=(
481 '(-s --stat)'{-s,--stat}'[show diff stat]'
482 '*:patches:__stg_patches_all'
483 + '(patch-selection)'
484 '(-a --applied)'{-a,--applied}'[show applied patches]'
485 '(-u --unapplied)'{-u,--unapplied}'[show unapplied patches]'
487 _arguments -s -S $subcmd_args
490 _stg-sink() {
491 __stg_add_args_help
492 __stg_add_args_keep
493 subcmd_args+=(
494 '(-n --nopush)'{-n,--nopush}'[do not push patches after sinking]'
495 '(-t --to)'{-t,--to=}'[sink patches below target patch]: :__stg_patches_applied'
496 ':patches:__stg_patches_all'
498 _arguments -s -S $subcmd_args
501 _stg-squash() {
502 __stg_add_args_help
503 __stg_add_args_hook
504 __stg_add_args_savetemplate
505 subcmd_args+=(
506 '(-n --name)'{-n,--name=}'[name for squashed patch]: :__stg_patches_all'
507 '*:patches:__stg_patches_all_allow_dups'
509 __stg_add_args_message
510 _arguments -s -S $subcmd_args
513 _stg-sync() {
514 # TODO: complete patches based on --ref-branch
515 __stg_add_args_help
516 subcmd_args+=(
517 + '(patches)'
518 '(-a --all)'{-a,--all}'[synchronize all applied patches]'
519 '*:patches:__stg_patches_all'
520 + '(source)'
521 '(-B --ref-branch)'{-B,--ref-branch}'[synchronize patches with branch]: :__stg_branch_stgit'
522 '(-s --series)'{-s,--series=}'[synchronize patches with series]: :_files'
524 _arguments -s -S $subcmd_args
527 _stg-top() {
528 __stg_add_args_help
529 __stg_add_args_branch
530 _arguments -s -S $subcmd_args
533 _stg-uncommit() {
534 __stg_add_args_help
535 subcmd_args+=(
536 - group-number
537 '(-n --number)'{-n+,--number=}'[push specified number of patches]:number'
538 ':prefix:'
539 - group-to
540 '(-t --to)'{-t,--to=}'[uncommit to the specified commit]:commit'
541 '(-x --exclusive)'{-x,--exclusive}'[exclude the commit specified by --to]'
542 - group-names
543 '*:names:'
545 _arguments -s -S $subcmd_args
548 _stg-undo() {
549 __stg_add_args_help
550 subcmd_args+=(
551 '--hard[discard changes in index/worktree]'
552 '(-n --number)'{-n+,--number=}'[number commands to undo]:number'
554 _arguments -s -S $subcmd_args
557 _stg-unhide() {
558 __stg_add_args_help
559 __stg_add_args_branch
560 subcmd_args+=(
561 ':patches:__stg_patches_hidden'
563 _arguments -s -S $subcmd_args
566 __stg_add_args_author() {
567 subcmd_args+=(
568 '--author=[set author details]'
569 '--authdate=[set author date]:date'
570 '--authemail=[set author email]:email'
571 '--authname=[set author name]:name'
575 __stg_add_args_branch() {
576 subcmd_args+=(
577 '(-b --branch)'{-b,--branch=}'[specify another branch]: :__stg_branch_stgit'
581 __stg_add_args_diffopts() {
582 # TODO: complete diff-opts values (with separators?)
583 subcmd_args+=(
584 '(-O --diff-opts)'{-O+,--diff-opts=}'[extra options for git diff]:opts'
588 __stg_add_args_edit() {
589 subcmd_args+=(
590 '(-e --edit)'{-e,--edit}'[invoke interactive editor]'
594 __stg_add_args_help() {
595 subcmd_args+=(
596 '(- *)'{-h,--help}'[show help message and exit]'
600 __stg_add_args_hook() {
601 subcmd_args+=(
602 '--no-verify[disable commit-msg hook]'
606 __stg_add_args_keep() {
607 subcmd_args+=(
608 '(-k --keep)'{-k,--keep}'[keep local changes]'
612 __stg_add_args_merged() {
613 subcmd_args+=(
614 '(-m --merged)'{-m,--merged}'[check for patches merged upstream]'
618 __stg_add_args_message() {
619 subcmd_args+=(
620 + '(message)'
621 '(-f --file)'{-f,--file=}'[use message file instead of invoking editor]: :_files'
622 '(-m --message)'{-m,--message=}'[specify message instead of invoking editor]:message'
626 __stg_add_args_savetemplate() {
627 subcmd_args+=(
628 '--save-template=[save message template to file and exit]: :_files'
632 __stg_add_args_sign() {
633 subcmd_args+=(
634 '--ack[add Acked-by line]'
635 '--review[add Reviewed-by line]'
636 '--sign[add Signed-off-by line]'
640 __stg_branch_all() {
641 declare -a all_branches
642 all_branches=(
643 ${${(f)"$(_call_program remote-branch-refs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/}
645 local expl
646 _wanted -V branches expl "branch" compadd $all_branches
649 __stg_branch_stgit() {
650 declare -a stg_branches
651 stg_branches=(
652 ${(u)${${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/}:/*.stgit/}}
654 local expl
655 _wanted -V branches expl "branch" compadd $stg_branches
658 __stg_files_relative() {
659 local prefix
660 prefix=$(_call_program gitprefix git rev-parse --show-prefix 2>/dev/null)
661 if (( $#prefix == 0 )); then
662 print $1
663 return
666 local file
667 local -a files
669 files=()
670 # Collapse "//" and "/./" into "/". Strip any remaining "/." and "/".
671 for file in ${${${${${(0)1}//\/\///}//\/.\///}%/.}%/}; do
672 integer i n
673 (( n = $#file > $#prefix ? $#file : $#prefix ))
674 for (( i = 1; i <= n; i++ )); do
675 if [[ $file[i] != $prefix[i] ]]; then
676 while (( i > 0 )) && [[ $file[i-1] != / ]]; do
677 (( i-- ))
678 done
679 break
681 done
683 files+=${(l@${#prefix[i,-1]//[^\/]}*3@@../@)}${file[i,-1]}
684 done
686 print ${(pj:\0:)files}
689 __stg_files_dirty() {
690 declare -a dirty_files
691 dirty_files=(
692 ${(f)"$(_call_program dirty-files git diff-index --name-only HEAD 2>/dev/null)"}
694 dirty_files=(${(0)"$(__stg_files_relative $dirty_files)"})
695 local expl
696 _wanted -V dirty-files expl "dirty files" _multi_parts - / dirty_files
699 __stg_files_known() {
700 declare -a known_files
701 known_files=(
702 ${(f)"$(_call_program known-files git ls-files 2>/dev/null)"}
704 local expl
705 _wanted -V known-files expl "known files" _multi_parts - / known_files
708 __stg_patches_all() {
709 declare -a patches
710 local expl
711 patches=(
712 ${(f)"$(_call_program all-patches stg series --noprefix --all 2>/dev/null)"}
714 _wanted -V all expl "patch" compadd ${patches:|words}
717 __stg_patches_all_allow_dups() {
718 declare -a patches
719 local expl
720 patches=(
721 ${(f)"$(_call_program all-patches stg series --noprefix --all 2>/dev/null)"}
723 _wanted -V all expl "patch" compadd ${patches}
726 __stg_patches_applied() {
727 declare -a patches
728 local expl
729 patches=(
730 ${(f)"$(_call_program applied-patches stg series --noprefix --applied 2>/dev/null)"}
732 _wanted -V applied expl "patch" compadd ${patches:|words}
735 __stg_patches_hidden() {
736 declare -a patches
737 local expl
738 patches=(
739 ${(f)"$(_call_program unhidden-patches stg series --noprefix --hidden 2>/dev/null)"}
741 _wanted -V unapplied expl "patch" compadd ${patches:|words}
744 __stg_patches_unapplied() {
745 declare -a patches
746 local expl
747 patches=(
748 ${(f)"$(_call_program unapplied-patches stg series --noprefix --unapplied 2>/dev/null)"}
750 _wanted -V unapplied expl "patch" compadd ${patches:|words}
753 __stg_patches_unhidden() {
754 declare -a patches
755 local expl
756 patches=(
757 ${(f)"$(_call_program unhidden-patches stg series --noprefix --applied --unapplied 2>/dev/null)"}
759 _wanted -V unapplied expl "patch" compadd ${patches:|words}
762 __stg_remotes() {
763 local remotes expl
764 remotes=(${(f)"$(_call_program remotes git remote 2>/dev/null)"})
765 _wanted remotes expl remote compadd "$@" -a - remotes
768 __stg_subcommands() {
769 _describe -t commands 'stgit command' _stg_cmds
772 __stg_caching_policy() {
773 [[ =$service -nt $1 ]]
776 _stgit() {
777 local curcontext="$curcontext" state line expl ret=1
778 typeset -A opt_args
780 # Special cases for git aliases
781 case "$words[2]" in
782 (add|mv|rm|status)
783 words[1]=git
785 (resolved)
786 words[1]=git
787 words[2]=add
789 esac
790 if [ "$words[1]" = git ]; then
791 _normal && ret=0
792 return ret
795 local update_policy
796 zstyle -s ":completion:*:*:stg:*" cache-policy update_policy
797 if [[ -z "$update_policy" ]]; then
798 zstyle ":completion:*:*:stg:*" cache-policy __stg_caching_policy
801 _arguments -C -A "-*" \
802 '(-)--help[print help information]' \
803 '(*)--version[display version information]' \
804 '1: :->command' \
805 '*:: :->args' && ret=0
807 if [[ -n $state ]] && (( ! $+_stg_cmds )); then
808 typeset -a _stg_cmds
809 if _cache_invalid stg-cmds || ! _retrieve_cache stg-cmds; then
810 _stg_cmds=(
811 ${${${(M)${(f)"$(stg help 2> /dev/null)"}## *}# }/#(#b)([^[:space:]]##)[[:space:]]##(*)/$match[1]:$match[2]}
813 if (( $? == 0 )); then
814 _store_cache stg-cmds _stg_cmds
815 else
816 unset _stg_cmds
821 case $state in
822 (command)
823 __stg_subcommands && ret=0
825 (args)
826 local -a subcmd_args
827 local subcmd=$words[1]
828 curcontext="${curcontext%:*:*}:stg-$subcmd:"
829 if ! _call_function ret _stg-$subcmd; then
830 _message "unknown sub-command: $subcmd"
833 esac
835 return ret
838 _stgit "$@"