2 # The following several shell functions and `compctl' commands
3 # that will configure the programmable command completion of
4 # the Z Shell (zsh) for the nmh mail system.
6 # You may need to edit where it says EDIT ME.
7 # These were orginally written for MH by Peter Stephenson
9 # The following three functions are best autoloaded.
11 # mhcomp completes folders (including subfolders).
12 # mhfseq completes sequence names and message numbers.
13 # mhfile completes files in standard nmh locations.
16 # Completion function for nmh folders. Works with
17 # both + (relative to top) and @ (relative to current).
20 local nword args pref char mhpath
28 # The $(...) here accounts for most of the time spent in this function.
29 if [[ $char = + ]]; then
31 # EDIT ME: use a hard wired value here: it's faster.
33 elif [[ $char = @ ]]; then
37 eval "reply=($mhpath/$pref*(N-/))"
39 # I'm frankly amazed that this next step works, but it does.
40 reply=(${reply#$mhpath/})
44 # Extract nmh message names and numbers for completion. Use of the
45 # correct folder, if it is not the current one, requires that it
46 # should be the previous command line argument. If the previous
47 # argument is `-draftmessage', a hard wired draft folder name is used.
50 local folder foldpath words pos nums
54 # Look for a folder name.
55 # First try the previous word.
56 if [[ $words[$pos-1] = [@+]* ]]; then
58 # Next look and see if we're looking for a draftmessage
59 elif [[ $words[$pos-1] = -draftmessage ]]; then
60 # EDIT ME: shortcut -- hard-wire draftfolder here
61 # Should really look for a +draftfolder argument.
64 # Else use the current folder ($folder empty)
66 if [[ $folder = +* ]]; then
67 # EDIT ME: use hard-wired path with + for speed.
68 foldpath=~/Mail/$folder[2,-1]
70 foldpath=$(mhpath $folder)
73 # Extract all existing message numbers from the folder.
74 nums=($foldpath/<->(N:t))
75 # If that worked, look for marked sequences.
77 # if you never use non-standard sequences, comment out
78 # or delete the next three lines.
80 nums=($nums $(mark $folder | awk -F: '{print $1}'))
83 # EDIT ME: `unseen' is the value of Unseen-Sequence, if it exists;
84 set -A reply next cur prev first last all unseen $nums
89 # Find an nmh file; for use with -form arguments and the like.
90 # Use with compctl -K mhfile.
95 # Array containing all the places nmh will look for templates etc.
96 mhfpath=(~/Mail /usr/local/nmh/lib)
98 # Emulate completeinword behaviour as appropriate
100 if [[ -o completeinword ]]; then
106 if [[ $1$2 = */* ]]; then
107 # path given: don't search nmh locations
108 eval "reply=($wordstr(.N))"
110 # no path: only search nmh locations.
111 eval "reply=(\$mhfpath/$wordstr(.N:t))"
115 # Note: you must type the initial + or @ of a folder name to get
116 # completion, even in places where only folder names are allowed.
117 # Abbreviations for options are not recognised. Hit tab to complete
118 # the option name first.
120 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
121 's[-]' -k "(all noall fast nofast header noheader help list nolist \
122 pack nopack pop push recurse norecurse total nototal)" -- folder folders
124 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
125 's[-]' -k "(sequence all noall recurse norecurse showzero noshowzero \
126 alpha noalpha fast nofast help)" -- flist flists
128 compctl -K mhfseq -x 's[+][@],c[-1,-draftfolder] s[+][@]' \
129 -K mhcomp -S / -q - 'c[-1,-draftmessage]' -K mhfseq - \
130 'C[-1,-(editor|whatnowproc)]' -c - \
131 's[-]' -k "(draftfolder draftmessage nodraftfolder editor noedit \
132 file form use nouse whatnowproc nowhatnowproc help)" - \
133 'c[-1,-form]' -K mhfile -- comp
135 compctl -K mhfseq -x 's[+][@]' \
136 -K mhcomp -S / -q - 'c[-1,-draftmessage]' -K mhfseq -\
137 's[-]' -k "(annotate noannotate cc nocc draftfolder nodraftfolder \
138 draftmessage editor noedit fcc filter form group nogroup inplace noinplace
139 query noquery width whatnowproc nowhatnowproc help)" - 'c[-1,(cc|nocc)]' \
140 -k "(all to cc me)" - 'C[-1,-(filter|form)]' -K mhfile - \
141 'C[-1,-(editor|whatnowproc)]' -c -- repl
143 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
144 's[-]' -k "(audit noaudit changecur nochangecur form format \
145 file silent nosilent truncate notruncate width help)" - \
146 'C[-1,-(audit|form)]' -K mhfile - 'c[-1,-file]' -f + -- inc
148 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
149 's[-]' -k "(sequence add delete list public nopublic zero nozero help)" -- \
152 compctl -K mhfseq -x 's[+][@]' \
153 -K mhcomp -S / -q - 'c[-1,-file]' -f - 'c[-1,-rmmprov]' -c - \
154 's[-]' -k "(draft link nolink preserve nopreserve src file \
155 rmmproc normmproc help)" -- refile
157 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
158 's[-]' -k "(clear noclear form format header noheader reverse noreverse \
159 file help width)" - 'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile -- scan
161 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
162 's[-]' -k "(draft form moreproc nomoreproc header noheader \
163 showproc noshowproc length width help)" - 'C[-1,-(show|more)proc]' -c - \
164 'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile - \
165 'c[-1,-length]' -s '$LINES' - 'c[-1,-width]' -s '$COLUMNS' -- show next prev
167 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
170 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
171 's[-]' -k "(after before cc date datefield from help list nolist \
172 public nopublic search sequence subject to zero nozero not or and \
173 lbrace rbrace)" -- pick
175 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
176 -k "(alias check draft draftfolder draftmessage help nocheck \
177 nodraftfolder)" -- whom
179 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
180 -k "(file part type list headers noheaders realsize norealsize nolist \
181 show serialonly noserialonly form pause nopause noshow store auto noauto \
182 nostore cache nocache rcache wcache check nocheck ebcdicsafe noebcdicsafe \
183 rfc934mode norfc934mode verbose noverbose help)" - \
184 'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile - \
185 'C[-1,-[rw]cache]' -k '(public private never ask)' -- mhn
187 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' -k '(help)' -- mhpath