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.
49 local folder foldpath words pos nums
53 # Look for a folder name.
54 # First try the previous word.
55 if [[ $words[$pos-1] = [@+]* ]]; then
58 # Else use the current folder ($folder empty)
60 if [[ $folder = +* ]]; then
61 # EDIT ME: use hard-wired path with + for speed.
62 foldpath=~/Mail/$folder[2,-1]
64 foldpath=$(mhpath $folder)
67 # Extract all existing message numbers from the folder.
68 nums=($foldpath/<->(N:t))
69 # If that worked, look for marked sequences.
71 # if you never use non-standard sequences, comment out
72 # or delete the next three lines.
74 nums=($nums $(mark $folder | awk -F: '{print $1}'))
77 # EDIT ME: `unseen' is the value of Unseen-Sequence, if it exists;
78 set -A reply next cur prev first last all unseen $nums
83 # Find an nmh file; for use with -form arguments and the like.
84 # Use with compctl -K mhfile.
89 # Array containing all the places nmh will look for templates etc.
90 mhfpath=(~/Mail /usr/local/nmh/lib)
92 # Emulate completeinword behaviour as appropriate
94 if [[ -o completeinword ]]; then
100 if [[ $1$2 = */* ]]; then
101 # path given: don't search nmh locations
102 eval "reply=($wordstr(.N))"
104 # no path: only search nmh locations.
105 eval "reply=(\$mhfpath/$wordstr(.N:t))"
109 # Note: you must type the initial + or @ of a folder name to get
110 # completion, even in places where only folder names are allowed.
111 # Abbreviations for options are not recognised. Hit tab to complete
112 # the option name first.
114 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
115 's[-]' -k "(all noall fast nofast header noheader help list nolist \
116 pack nopack pop push recurse norecurse total nototal)" -- folder folders
118 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
119 's[-]' -k "(sequence all noall recurse norecurse showzero noshowzero \
120 alpha noalpha fast nofast help)" -- flist flists
122 compctl -K mhfseq -x 's[+][@],c[-1] s[+][@]' \
123 -K mhcomp -S / -q - 'c[-1]' -K mhfseq - \
124 'C[-1,-(editor|whatnowproc)]' -c - \
125 's[-]' -k "(editor noedit \
126 form use nouse whatnowproc help)" - \
127 'c[-1,-form]' -K mhfile -- comp
129 compctl -K mhfseq -x 's[+][@]' \
130 -K mhcomp -S / -q - 'c[-1]' -K mhfseq -\
131 's[-]' -k "(annotate noannotate cc nocc \
132 editor noedit filter nofilter form group nogroup \
133 query noquery width whatnowproc help)" - 'c[-1,(cc|nocc)]' \
134 -k "(all to cc me)" - 'C[-1,-(filter|form)]' -K mhfile - \
135 'C[-1,-(editor|whatnowproc)]' -c -- repl
137 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
138 's[-]' -k "(audit noaudit changecur nochangecur form \
139 file silent nosilent truncate notruncate width help)" - \
140 'C[-1,-(audit|form)]' -K mhfile - 'c[-1,-file]' -f + -- inc
142 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
143 's[-]' -k "(sequence add delete list public nopublic zero nozero help)" -- \
146 compctl -K mhfseq -x 's[+][@]' \
147 -K mhcomp -S / -q - 'c[-1,-file]' -f - \
148 's[-]' -k "(link nolink src file help)" -- refile
150 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
152 file help width)" - 'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile -- scan
154 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
155 's[-]' -k "(file form part type help)" - \
156 'c[-1,-file]' -f - 'c[-1,-form]' -K mhfile - -- show next prev
158 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
161 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
162 's[-]' -k "(after before cc date datefield from help list nolist \
163 public nopublic search sequence subject to zero nozero not or and \
164 lbrace rbrace)" -- pick
166 compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' -k '(help)' -- mhpath