diff options
Diffstat (limited to 'Completion/Unix')
-rw-r--r-- | Completion/Unix/Command/_elm | 21 | ||||
-rw-r--r-- | Completion/Unix/Command/_mail | 21 | ||||
-rw-r--r-- | Completion/Unix/Command/_mutt | 58 | ||||
-rw-r--r-- | Completion/Unix/Command/_pine | 32 | ||||
-rw-r--r-- | Completion/Unix/Type/_email_addresses | 172 |
5 files changed, 204 insertions, 100 deletions
diff --git a/Completion/Unix/Command/_elm b/Completion/Unix/Command/_elm index 34a30649c..2918a5de0 100644 --- a/Completion/Unix/Command/_elm +++ b/Completion/Unix/Command/_elm @@ -1,9 +1,7 @@ #compdef elm -local curcontext="$curcontext" state line expl suf - -_arguments -C -s \ - '::recipient:->userhost' \ +_arguments -s \ + '::recipient:_email_addresses' \ '-a[use the arrow pointer regardless]' \ '-A+[attach file]:file attachment:_files' \ '-c[check the given aliases only]:*:alias' \ @@ -17,17 +15,4 @@ _arguments -C -s \ '-V[enable sendmail voyeur mode]' \ '-v[display elm version]' \ '-w[write .elm/elmrc]' \ - '-z[start only if new messages]' && return 0 - -if [[ "$state" = userhost ]]; then - if compset -P '*@'; then - _description hosts expl 'remote host name' - _hosts "$expl[@]" && return 0 - else - compset -S '@*' || suf='@' - _description users expl 'login name' - _users "$expl[@]" -q -S "$suf" && return 0 - fi -fi - -return 1 + '-z[start only if new messages]' diff --git a/Completion/Unix/Command/_mail b/Completion/Unix/Command/_mail index 82a3a59d0..90c75359d 100644 --- a/Completion/Unix/Command/_mail +++ b/Completion/Unix/Command/_mail @@ -1,24 +1,9 @@ -#compdef mail mailx Mail mush zmail nail +#compdef mail mailx=mail Mail=mail mush zmail nail=mail -local curcontext="$curcontext" state line expl suf - -_arguments -C -s \ +_arguments -s \ '(-f -u)*-b[specify a BCC recipient]:BCC recipient:->userhost' \ '(-f -u)*-c[specify a CC recipient]:CC recipient:->userhost' \ '(-b -c -u -s *)-f+[specify mail folder]:mailbox:_mailboxes' \ '(-f -u)-s+[specify a subject]:subject:' \ "(-b -c -f -s *)-u+[read specified user's mail]:user:_users" \ - '(-f -u)*:recipient:->userhost' && return 0 - -if [[ "$state" = userhost ]]; then - if compset -P '*@'; then - _description hosts expl 'remote host name' - _hosts "$expl[@]" && return 0 - else - compset -S '@*' || suf='@' - _description users expl 'login name' - _users "$expl[@]" -q -S "$suf" && return 0 - fi -fi - -return 1 + "(-f -u)*:recipient:_email_addresses -n $service" diff --git a/Completion/Unix/Command/_mutt b/Completion/Unix/Command/_mutt index 21e383484..c9ff98af4 100644 --- a/Completion/Unix/Command/_mutt +++ b/Completion/Unix/Command/_mutt @@ -1,39 +1,23 @@ #compdef mutt -local curcontext="$curcontext" state line expl suf -typeset -A opt_args - -_arguments -C -s \ - '::recipient:->userhost' \ - '*-a[attach file using MIME]:file attachment:_files' \ - '*-b[specify a BCC recipient]:BCC recipient:->userhost' \ - '*-c[specify a CC recipient]:CC recipient:->userhost' \ - '-e+[specify a post-init configuration command]:post-init configuration:' \ - '-f+[specify mailbox to load]:mailbox: _mailboxes' \ - '-F+[specify an init file]:init file:_files' \ - '-h[display help]' \ - '-H+[specify a draft file for message]:draft file:_files' \ - '-i+[specify file to include in message]:include file:_files' \ - '-m+[specify default mailbox type]:mailbox type:(mbox MMDF MH Maildir)' \ - '-n[bypass system configuration]' \ - '-p[resume postponed message]' \ - '-R[open in read-only mode]' \ - '-s+[specify a subject]:subject:' \ - '-v[display mutt version]' \ - '-x[emulate mailx compose]' \ - '-y[start listing mailboxes]' \ - '-z[start only if new messages]' \ - '-Z[open first mailbox with new mail]' && return 0 - -if [[ "$state" = userhost ]]; then - if compset -P '*@'; then - _description hosts expl 'remote host name' - _hosts "$expl[@]" -q -S, && return 0 - else - compset -S '@*' || suf='@' - _description users expl 'login name' - _users "$expl[@]" -q -S "$suf" && return 0 - fi -fi - -return 1 +_arguments -s \ + '::recipient:_email_addresses -n mutt' \ + '*-a[attach file using MIME]:file attachment:_files' \ + '*-b[specify a BCC recipient]:BCC recipient:_email_addresses -n mutt' \ + '*-c[specify a CC recipient]:CC recipient:_email_addresses -n mutt' \ + '-e+[specify a post-init configuration command]:post-init configuration:' \ + '-f+[specify mailbox to load]:mailbox: _mailboxes' \ + '-F+[specify an init file]:init file:_files' \ + '-h[display help]' \ + '-H+[specify a draft file for message]:draft file:_files' \ + '-i+[specify file to include in message]:include file:_files' \ + '-m+[specify default mailbox type]:mailbox type:(mbox MMDF MH Maildir)' \ + '-n[bypass system configuration]' \ + '-p[resume postponed message]' \ + '-R[open in read-only mode]' \ + '-s+[specify a subject]:subject:' \ + '-v[display mutt version]' \ + '-x[emulate mailx compose]' \ + '-y[start listing mailboxes]' \ + '-z[start only if new messages]' \ + '-Z[open first mailbox with new mail]' diff --git a/Completion/Unix/Command/_pine b/Completion/Unix/Command/_pine index 9ee0b44c9..1902074a8 100644 --- a/Completion/Unix/Command/_pine +++ b/Completion/Unix/Command/_pine @@ -1,9 +1,8 @@ #compdef pine pinef -local curcontext="$curcontext" state line expl suf local optfile getopts='pine -conf' sortorder lusortorder opts send idx -if [[ -n $+_cache_pine_options ]]; then +if (( $#_cache_pine_options )); then for optfile in ~/.pinerc /etc/pine.conf; do if [[ -f $optfile ]]; then getopts="cat $optfile" @@ -20,7 +19,7 @@ opts=( -h -v -F -conf -create_lu -pinerc -copy_abook -copy_pinerc) # exclusive idx=( -f -c -i -I -n -o -sort ) # options used when viewing messages send=( -attach -attachlist -attach_and_delete -url ) # options when sending -_arguments -C -s \ +_arguments -s \ "($opts $idx $send -bail -d -k -z -r -p -P *)-h[display help]" \ "($opts $idx $send -bail -d -k -z -r -p -P *)-v[display version information]" \ "($opts $idx $send -r *)-F+[specify file to open and page through]:file:_files" \ @@ -32,7 +31,7 @@ _arguments -C -s \ "($opts $idx -url)-attach[go directly into composer with given file]:file:_files" \ "($opts $idx -url)-attachlist[go to composer with given files]:file:_files" \ "($opts $idx -url)-attach_and_delete[go to composer, attach file, delete when finished]:file:_files" \ - "($opts $idx $send)-url[open the given URL]:url:->url" \ + "($opts $idx $send)-url[open the given URL]:url:_email_addresses -c -P mailto\:" \ "($opts $send)-f+[specify mailbox to load]:mailbox: _mailboxes" \ "($opts $send)-c+[specify context to apply to -f arg]: :_guard '[0-9]#' number" \ "($opts $send)-sort[specify sort order of folder]:sort order:(${(j: :)sortorder})" \ @@ -48,26 +47,5 @@ _arguments -C -s \ \(${(j. .)opts:#-F}')-P+[use alternate pine.conf file]:alternate pine.conf:_files' \ \(${(j. .)opts:#-F}')-x[use configuration exceptions file]:configuration exceptions file:_files' \ \(${(j. .)opts:#-F}")-bail[exit if pinerc file doesn't already exist]" \ - '*::recipient:->userhost' \ - ${^_cache_pine_options}':option value' && return 0 - -if [[ "$state" = url ]]; then - if compset -P 'mailto:'; then - state=userhost - else - compadd -S: mailto && return 0 - fi -fi - -if [[ "$state" = userhost ]]; then - if compset -P '*@'; then - _description hosts expl 'remote host name' - _hosts "$expl[@]" && return 0 - else - compset -S '@*' || suf='@' - _description users expl 'login name' - _users "$expl[@]" -q -S "$suf" && return 0 - fi -fi - -return 1 + '*::recipient:_email_addresses -n pine' \ + ${^_cache_pine_options}':option value' diff --git a/Completion/Unix/Type/_email_addresses b/Completion/Unix/Type/_email_addresses new file mode 100644 index 000000000..fe4f252c8 --- /dev/null +++ b/Completion/Unix/Type/_email_addresses @@ -0,0 +1,172 @@ +#autoload +# options: +# +# -n plugin - can complete nicknames from specified plugin +# -s sep - complete a list of addresses separated by specified character +# -c - e-mail address must be of form user@host (no comments or aliases) +# +# Plugins are written as separate functions with names starting `_email-'. +# They should either do their own completion or return the addresses in the +# ali array in the form 'alias:address' and return 300. The -c option is +# passed on to plugins (and -n could be if needed ever). New plugins will be +# picked up and run automatically. + +# plugins +(( $+functions[_email-mail] )) || +_email-mail() { + ali=( ${${${(M)${(f)"$(<$files[$plugin])"}:#alias*}##alias[[:blank:]]##}/[[:blank:]]##/:} ) + return 300 +} +(( $+functions[_email-mutt] )) || _email-mutt() { _email-mail } +(( $+functions[_email-mush] )) || _email-mush() { _email-mail } + +(( $+functions[_email-MH] )) || +_email-MH() { + ali=( ${${(f)"$(_call_program aliases ali)"}/: /:} ) + return 300 +} + +(( $+functions[_email-pine] )) || +_email-pine() { + ali=( ${${${${${(f)"$(<~/.addressbook)"}:#*DELETED*}:#\ *}/ [^ ]# /:}%% *} ) + return 300 +} + +(( $+functions[_email-ldap] )) || +_email-ldap() { + local -a expl ali res filter + local -A opts + local dn cn mail + + zparseopts -D -E -A opts c + + zstyle -a ":completion:${curcontext}:$curtag" filter filter + (( $#filter )) || return + + filter=( "("${filter}"=${PREFIX}*${SUFFIX})" ) + (( $#filter > 1 )) && filter="(|"${(j..)filter}")" + res=( ${(f)"$(_call_program $curtag ldapsearch -LLL \$filter cn mail 2>/dev/null)"} ) + (( $#res > 1 )) || return + + for dn cn mail in "${res[@]}"; do + if (( $+opts[-c] )); then + ali+=( "${mail#*: }" ) + else + cn="${cn#*: }" + [[ $cn = *$~__specials* ]] && cn="\"$cn\"" + ali+=( "$cn <${mail#*: }>" ) + fi + done + compstate[insert]=menu + _wanted email-ldap expl 'matching names' \ + compadd -U -i "$IPREFIX" -I "$ISUFFIX" "$@" -a - ali +} + +(( $+functions[_email-local] )) || +_email-local() { + local suf opts + zparseopts -D -E -A opts c S:=suf + + if compset -P '*@'; then + _hosts "$@" "$suf[@]" + else + suf=() + compset -S '@*' || suf=( -qS @ ) + _users "$suf[@]" "$@" + fi +} + +_email_addresses() { + local -a plugins ali list args + local -A opts files + local plugin rcfile expl ret fret + + local __specialx='][()<>@,;:\\".' + local __spacex=" " # Space, tab + local __specials="[$__specialx]" + local __atom="[^$__specialx$__spacex]##" + local __space="[$__spacex]#" # Really, space or comment + local __qtext='[^"\\]' + local __qpair='\\?' + local __beginq='"' + local __endq='(|[^\\])"' + local __dot="$__space.$__space" + + local __domainref="$__atom" + local __domainlit='\[([^]]|'"$__qpair"')#(|[^\\])\]' + local __quotedstring="$__beginq($__qtext|$__qpair)#$__endq" + local __word="($__atom|$__quotedstring)" + local __phrase="($__space$__word$__space)#" # Strictly, should use `##' + local __localpart="$__word($__dot$__word)#" + + local __subdomain="($__domainref|$__domainlit)" + local __domain="$__subdomain($__dot$__subdomain)#" + local __addrspec="$__localpart$__space@$__space$__domain" + + local __addresses="($__qtext|$__quotedstring)##" + + zparseopts -D -E -A opts n: s: c + set -- "$@" -M 'r:|[.@]=* r:|=* m:{a-zA-Z}={A-Za-z}' + + if [[ -n $opts[-s] ]]; then + # remove up to the last unquoted separator + if [[ ${(Q)PREFIX} = (#b)($~__addresses$opts[-s])* ]]; then + IFS="$opts[-s]" eval 'compset -P $(( ${#${=${:-x${match[1]}x}}} - 1 )) "*${opts[-s]}"' + fi + + # for the suffix, I'm too lazy to work out how to preserve quoted separators + compset -S "$opts[-s]*" || set -- -q -S "$opts[-s]" "$@" + fi + + # get list of all plugins except any with missing config files + files=( mutt ~/.muttrc mush ~/.mushrc mail ${MAILRC:-~/.mailrc} pine ~/.addressbook ) + plugins=( + ${${(k)functions[(I)_email-*]#*-}:#(${(kj.|.)~files})} + $files(Ne:'REPLY=( ${(k)files[(r)$REPLY]} ):') + ) + + ret=1 + _tags email-$plugins + while _tags; do + for plugin in $plugins; do + if _requested email-$plugin; then + while _next_label email-$plugin expl 'email address'; do + + args=() + if (( $+opts[-c] )) || zstyle -t \ + ":completion:${curcontext}:$curtag" strip-comments + then + args=( '-c' ) + fi + + if ! _call_function fret _email-$plugin "$@" $args; then + _message "$plugin: plugin not found" + continue + fi + ret=$(( ret && fret )) + + if (( fret == 300 )); then + if (( ! $+opts[-c] )) && [[ $opts[-n] = $plugin ]]; then + zformat -a list ' -- ' "${ali[@]}" + _wanted mail-aliases expl 'alias' compadd "$@" \ + -d list - ${ali%%:*} && ret=0 + else + if (( $#args )); then + ali=( ${(SM)${ali#*:}##$~__addrspec} ) + else + # remove lines not containing `@' as they probably aren't addresses + ali=( "${(@)${(M@)ali:#*@*}#*:}" ) + fi + compadd -a "$@" "$expl[@]" ali && ret=0 + fi + fi + done + fi + done + (( ret )) || return 0 + done + + return 1 +} + +_email_addresses "$@" |