Skip to content

Commit 7dca36f

Browse files
committed
Zsh completions for stg email
1 parent 97ba3ca commit 7dca36f

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed

completion/stgit.zsh

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,157 @@ _stg-edit() {
318318
_arguments -s -S $subcmd_args
319319
}
320320

321+
_stg-email() {
322+
local -a subcmd_args
323+
local curcontext="$curcontext" state line
324+
__stg_add_args_help
325+
__stg_add_args_color
326+
subcmd_args+=(
327+
'(-): :->command'
328+
'(-)*:: :->option-or-argument'
329+
)
330+
331+
integer ret=1
332+
333+
_arguments -s -S $subcmd_args && ret=0
334+
335+
case $state in
336+
(command)
337+
local -a command_list=(
338+
format:'format patches as email files'
339+
send:'send patches as emails'
340+
help:'show help for given subcommand'
341+
)
342+
_describe -t commands 'email command' command_list
343+
;;
344+
(option-or-argument)
345+
curcontext=${curcontext%:*:*}:stg-email-$words[1]
346+
if ! _call_function ret _stg-email-$words[1]; then
347+
_message "unknown subcommand: $words[1]"
348+
fi
349+
;;
350+
esac
351+
return ret
352+
}
353+
354+
_stg-email-format() {
355+
local curcontext=$curcontext state line ret=1
356+
local -a subcmd_args
357+
__stg_add_args_help
358+
__stg_add_args_color
359+
__stg_add_args_branch
360+
subcmd_args+=(
361+
'(-o --output-directory)'{-o+,--output-directory=}'[store resulting files in given directory]: :_directories'
362+
'(-n --numbered -N --no-numbered -k --keep-subject)'{-n,--numbered}'[name output in \[PATCH n/m\] format]'
363+
'(-n --numbered -N --no-numbered -k --keep-subject)'{-N,--no-numbered}'[name output in \[PATCH\] format]'
364+
'--start-number=[start numbering patches at given number]: :_numbers -l 1 "patch number"'
365+
'--numbered-files[use only number for file name]'
366+
'(-n --numbered -N --no-numbered -k --keep-subject --rfc --subject-prefix)'{-k,--keep-subject}"[don't strip/add \[PATCH\] from the first line of the commit message]"
367+
'(-s --signoff)'{-s,--signoff}'[add Signed-off-by: trailer to the commit message]'
368+
'( --inline)--attach[create attachments instead of inlining patches]'
369+
'(--attach )--inline[inline patches]'
370+
'(--thread )--no-thread[do not thread messages]'
371+
'( --no-thread)--thread=-[make the second and subsequent mails refer to the first]::style:((shallow\:"all refer to the first"
372+
deep\:"each refers to the previous"))'
373+
'--in-reply-to=[make the first mail a reply to the given message]:message id'
374+
'(-v --reroll-count)'{-v+,--reroll-count=}'[mark the series as the <n>-th iteration of the topic]: :_numbers iteration'
375+
'(-k --keep-subject --subject-prefix)--rfc[use \[RFC PATCH\] instead of \[PATCH\]]'
376+
'(-k --keep-subject --rfc)--subject-prefix=[use the given prefix instead of \[PATCH\]]:prefix'
377+
'(--no-to)*--to=[add To: header to email headers]: :_email_addresses'
378+
'--no-to[discard all To: headers added so far]'
379+
'(--no-cc)*--cc=[add Cc: header to email headers]: :_email_addresses'
380+
'--no-cc[discard all Cc: headers added so far]'
381+
'*--add-header=[add an arbitrary header to email headers]:header' \
382+
'--cover-letter[generate a cover letter]'
383+
'( --no-signature --signature-file)--signature=[add a signature]:signature'
384+
'(--signature --signature-file)--no-signature[do not add a signature]'
385+
'(--signature --no-signature )--signature-file=[use contents of file as signature]: :_files'
386+
'--base=[add prerequisite tree info to the patch series]:prereq commit:__stg_revisions'
387+
'--suffix=[use the given suffix for filenames]:filename suffix'
388+
'(-q --quiet)'{-q,--quiet}'[suppress the output of the names of generated files]'
389+
'--no-binary[do not output contents of changes in binary files, only note that they differ]'
390+
'--zero-commit[output all-zero hash in From header]'
391+
'--progress[show progress while generating patches]'
392+
'--interdiff=[insert interdiff against previous patch series in cover letter or single patch]:reference to tip of previous series:__stg_revisions'
393+
'--range-diff=[insert range-diff against previous patch series in cover letter or single patch]:reference to tip of previous series:__stg_revisions'
394+
'--creation-factor=[for range-diff, specify weighting for creation]:weighting (percent)'
395+
+ '(sources)'
396+
'(-a --all)'{-a,--all}'[format all applied patches]: :_files'
397+
': :->patch-or-patch-range'
398+
)
399+
_arguments -s -S $subcmd_args && ret=0
400+
401+
case $state in
402+
(patch-or-patch-range)
403+
__stg_patchrange --suggest-range && ret=0
404+
;;
405+
esac
406+
407+
return ret
408+
}
409+
410+
_stg-email-send() {
411+
local -a subcmd_args
412+
__stg_add_args_help
413+
__stg_add_args_color
414+
subcmd_args+=(
415+
'(-a --all)'{-a,--all}'[send all applied patches]: :_files'
416+
'--from=[specify sender]:email address:_email_addresses'
417+
'--to=[specify the primary recipient of the emails]: :_email_addresses'
418+
'--cc=[starting Cc: value for each email]: :_email_addresses'
419+
'--bcc=[Bcc: value for each email]: :_email_addresses'
420+
'--subject=[specify the initial subject of the email thread]:subject'
421+
'--reply-to=[specify Reply-To address]:email address:_email_addresses'
422+
'--in-reply-to=[specify contents of first In-Reply-To header]:message-id'
423+
'--compose[edit introductory message for patch series]'
424+
'--identity=[specify configuration identity]: :__stg_email_send_identities'
425+
'--no-thread[do not set In-Reply-To: and References: headers]'
426+
'--confirm[specify type of confirmation required before sending]: :((
427+
always\:"always confirm before sending"
428+
never\:"never confirm before sending"
429+
cc\:"confirm before sending to automatically added Cc-addresses"
430+
compose\:"confirm before sending first message when using --compose"
431+
auto\:"same as cc together with compose"
432+
))'
433+
'--quiet[be less verbose]'
434+
'--dry-run[do everything except actually sending the emails]'
435+
'(- *)--dump-aliases[dump configured aliases and exit]'
436+
'*: : _alternative -O expl
437+
"files:file:_files"
438+
"patchrange::__stg_patchrange --suggest-range"'
439+
)
440+
_arguments -s -S $subcmd_args
441+
}
442+
443+
_stg-email-help() {
444+
local -a subcmd_args
445+
local curcontext="$curcontext" state line
446+
subcmd_args+=(
447+
'(-): :->command'
448+
'(-)*:: :->option-or-argument'
449+
)
450+
451+
integer ret=1
452+
453+
_arguments -s -S $subcmd_args && ret=0
454+
455+
case $state in
456+
(command)
457+
local -a command_list=(
458+
format:'format patches as email files'
459+
send:'send patches as emails'
460+
help:'show help for given subcommand'
461+
)
462+
_describe -t commands 'email command' command_list
463+
;;
464+
(option-or-argument)
465+
curcontext=${curcontext%:*:*}:stg-email-$words[1]-help
466+
_call_function ret _stg-email-$words[1]-help
467+
;;
468+
esac
469+
return ret
470+
}
471+
321472
_stg-export() {
322473
local -a subcmd_args
323474
__stg_add_args_help
@@ -930,6 +1081,33 @@ __stg_git_diff_opts() {
9301081
_wanted git-diff-options expl "diff option" compadd -a diff_opts
9311082
}
9321083

1084+
__stg_revisions () {
1085+
_alternative \
1086+
"heads::__stg_heads" \
1087+
"commit-tags::__stg_commit_tags" \
1088+
"patch-refs::__stg_patch_refs"
1089+
}
1090+
1091+
__stg_commit_tags () {
1092+
local expl
1093+
declare -a tags
1094+
1095+
tags=(${${(M)${(f)"$(_call_program commit-tag-refs "git ${__stg_C_args} for-each-ref --format='%(*objecttype)%(objecttype) %(refname)' refs/tags 2>/dev/null")"}:#commit(tag|) *}#commit(tag|) refs/tags/})
1096+
__stg_git_command_successful $pipestatus || return 1
1097+
1098+
_wanted commit-tags expl "commit tag" compadd -M 'r:|/=* r:|=*' "$@" -o numeric -a - tags
1099+
}
1100+
1101+
__stg_patch_refs () {
1102+
local expl
1103+
declare -a refs
1104+
1105+
refs=(${(f)"$(_call_program patch-refs "git ${__stg_C_args} for-each-ref --format='%(refname:lstrip=2)' refs/patches 2>/dev/null")"})
1106+
__stg_git_command_successful $pipestatus || return 1
1107+
1108+
_wanted commit-tags expl "patch ref" compadd -p refs/patches/ -M 'r:|/=* r:|=*' "$@" -o numeric -a - refs
1109+
}
1110+
9331111
__stg_heads () {
9341112
_alternative 'heads-local::__stg_heads_local' 'heads-remote::__stg_heads_remote'
9351113
}
@@ -975,6 +1153,22 @@ __stg_git_command_successful () {
9751153
return 0
9761154
}
9771155

1156+
__stg_config_sections () {
1157+
local regex tag desc
1158+
local -a groups
1159+
1160+
regex=$1
1161+
tag=$2
1162+
desc=$3
1163+
1164+
groups=(${${${(0)"$(_call_program $tag "git ${__stg_C_args} config -z --get-regexp -- ${(q)regex}")"}#*.}%%.[^.]##$'\n'*})
1165+
_describe -t $tag $desc groups
1166+
}
1167+
1168+
__stg_email_send_identities () {
1169+
__stg_config_sections '^sendemail\..+\.[^.]+$' identities 'sendemail identity'
1170+
}
1171+
9781172
__stg_git_describe_commit () {
9791173
__stg_git_describe_branch $1 $2 $3 -M 'r:|/=* r:|=*' "${(@)argv[4,-1]}"
9801174
}

0 commit comments

Comments
 (0)