1#compdef ali anno burst comp dist flist flists folder folders forw inc mark mhlist mhmail mhn mhparam mhpath mhshow mhstore msgchk next packf pick prev refile repl rmf rmm scan show sortm whom 2 3if [[ -z $commands[mhpath] ]]; then 4 _message "MH commands are not available" 5 return 1 6fi 7 8# Completion for all possible MH commands. 9local mymhdir=${$(_call_program mhpath mhpath + 2>/dev/null):-~/Mail} 10local mhlib=/usr/lib/mh 11 12local prev="$words[CURRENT-1]" expl 13 14if compset -P 1 -; then 15 # get list of options, which MH commands can generate themselves 16 # awk is just too icky to use for this, sorry. send me one if 17 # you come up with it. 18 local -a options disp 19 options=( 20 $($words[1] -help | perl -ne 'if (/^\s*-\(?(\S+)/) { 21 $n = $1; 22 $n =~ s/\)//g; 23 print $n =~ s/^\[([a-z]+)\]// ? "$n\n$1$n\n" : "$n\n"; 24 }') 25 ) 26 if zstyle -t ":completion:${curcontext}:options" prefix-hidden; then 27 _wanted options expl option compadd -d disp - "$options[@]" 28 else 29 disp=( -${options} ) 30 _wanted options expl option compadd -d disp - "$options[@]" 31 fi 32 return 33elif compset -P 1 '[+@]' || [[ "$prev" = -draftfolder ]]; then 34 # Complete folder names. 35 local mhpath 36 37 if [[ $IPREFIX != '@' ]]; then 38 [[ $IPREFIX = '+' ]] || IPREFIX=+ 39 mhpath=$mymhdir 40 else 41 mhpath=$(mhpath) 42 fi 43 44 _wanted files expl 'MH folder' _path_files -W mhpath -/ 45elif [[ "$prev" = -(editor|(whatnow|rmm|show|more)proc) ]]; then 46 _command_names -e 47elif [[ "$prev" = -file ]]; then 48 _files 49elif [[ "$prev" = -(form|audit|filter) ]]; then 50 # Need some MH template file, which may be in our own MH directory 51 # or with the standard library. 52 local mhfpath 53 # This is the only place we need mhlib, so leave the test till here. 54 mhlib=${${$(mhparam mhlproc 2>/dev/null):h}:-/usr/lib/mh} 55 mhfpath=($mymhdir $mhlib) 56 57 _wanted files expl 'MH template file' _files -W mhfpath -g '*(-.)' 58elif [[ $service = mhmail ]]; then 59 _email_addresses 60elif [[ "$prev" = -(no|)cc ]]; then 61 _wanted -C "$prev" values expl 'CC address' compadd all to cc me 62elif [[ "$prev" = -[rw]cache ]]; then 63 _wanted -C "$prev" values expl cache compadd public private never ask 64elif [[ "$prev" = -textfield ]]; then 65 _wanted -C "$prev" -x headers expl header compadd -M 'm:{a-zA-Z}={A-Za-z}' \ 66 Subject From To cc 67elif [[ "$prev" = -datefield ]]; then 68 _wanted -C "$prev" -x headers expl header compadd -M 'm:{a-zA-Z}={A-Za-z}' \ 69 Delivery-Date 70elif [[ $service = mhparam ]]; then 71 _wanted parameters expl 'MH parameter' compadd - \ 72 ${${(f)"$(mhparam -all)"}%%:*} 73elif [[ $service = ali ]]; then 74 _email_addresses -n MH 75elif compset -P '*:'; then 76 _message -e number 'number of messages' 77else 78 # Generate sequences. 79 local foldnam folddir f sequences mhneg ret=1 80 81 compset -P '*-' # ignore start of message range 82 83 for f in $words; do 84 [[ $f = [@+]* ]] && foldnam=$f 85 done 86 if [[ $foldnam = '+'* ]]; then 87 folddir=$mymhdir/${foldnam#+} 88 elif [[ $foldnam = '@'* ]]; then 89 folddir=$(mhpath)/${foldnam#@} 90 else 91 folddir=$(mhpath) 92 # leaving foldnam empty works here 93 fi 94 95 sequences=( ${${(f)"$(mark $foldnam 2>/dev/null)"}%%:*} ) 96 mhneg="$(mhparam Sequence-Negation)" && sequences=( {,$mhneg}$^sequences ) 97 sequences+=( all first last prev next ) 98 _tags sequences 99 while _tags; do 100 while _next_label sequences expl sequence; do 101 compadd -S ' ' -r '-: \t\n\-' "$expl[@]" -a sequences && ret=0 102 _path_files -S ' ' -r '-: \t\n\-' "$expl[@]" -W folddir -g '<->(-.)' && 103 ret=0 104 done 105 (( ret )) || return 0 106 done 107 return ret 108fi 109