source: trunk/third/nmh/ZSH.COMPLETION @ 12455

Revision 12455, 6.4 KB checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12454, which included commits to RCS files with non-trunk default branches.
Line 
1#
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.
5#
6# You may need to edit where it says EDIT ME.
7# These were orginally written for MH by Peter Stephenson
8
9# The following three functions are best autoloaded.
10#
11# mhcomp completes folders (including subfolders).
12# mhfseq completes sequence names and message numbers.
13# mhfile completes files in standard nmh locations.
14
15#
16# Completion function for nmh folders.  Works with
17# both + (relative to top) and @ (relative to current).
18#
19function mhcomp {
20  local nword args pref char mhpath
21  read -nc nword
22  read -cA args
23
24  pref=$args[$nword]
25  char=$pref[1]
26  pref=$pref[2,-1]
27
28  # The $(...) here accounts for most of the time spent in this function.
29  if [[ $char = + ]]; then
30  #    mhpath=$(mhpath +)
31  # EDIT ME: use a hard wired value here: it's faster.
32    mhpath=~/Mail
33  elif [[ $char = @ ]]; then
34    mhpath=$(mhpath)
35  fi
36
37  eval "reply=($mhpath/$pref*(N-/))"
38
39  # I'm frankly amazed that this next step works, but it does.
40  reply=(${reply#$mhpath/})
41}
42
43#
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.
48#
49mhfseq() {
50  local folder foldpath words pos nums
51  read -cA words
52  read -cn pos
53
54  # Look for a folder name.
55  # First try the previous word.
56  if [[ $words[$pos-1] = [@+]* ]]; then
57    folder=$words[$pos-1]
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.
62    folder=+drafts
63  fi
64  # Else use the current folder ($folder empty)
65
66  if [[ $folder = +* ]]; then
67  # EDIT ME:  use hard-wired path with + for speed.
68    foldpath=~/Mail/$folder[2,-1]
69  else
70    foldpath=$(mhpath $folder)
71  fi
72
73  # Extract all existing message numbers from the folder.
74  nums=($foldpath/<->(N:t))
75  # If that worked, look for marked sequences.
76  # EDIT ME
77  # if you never use non-standard sequences, comment out
78  # or delete the next three lines.
79  if (( $#nums )); then
80    nums=($nums $(mark $folder | awk -F: '{print $1}'))
81  fi
82
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
85
86}
87
88#
89# Find an nmh file; for use with -form arguments and the like.
90# Use with compctl -K mhfile.
91#
92mhfile () {
93  local mhfpath file
94  # EDIT ME
95  # Array containing all the places nmh will look for templates etc.
96  mhfpath=(~/Mail /usr/local/nmh/lib)
97
98  # Emulate completeinword behaviour as appropriate
99  local wordstr
100  if [[ -o completeinword ]]; then
101    wordstr='$1*$2'
102  else
103    wordstr='$1$2*'
104  fi
105
106  if [[ $1$2 = */* ]]; then
107    # path given: don't search nmh locations
108    eval "reply=($wordstr(.N))"
109  else
110    # no path:  only search nmh locations.
111    eval "reply=(\$mhfpath/$wordstr(.N:t))"
112  fi
113}
114
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.
119
120compctl -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
123
124compctl -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
127
128compctl -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
134
135compctl -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
142
143compctl -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
147
148compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - \
149  's[-]' -k "(sequence add delete list public nopublic zero nozero help)" -- \
150  mark
151
152compctl -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
156
157compctl -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
160
161compctl -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
166
167compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
168  -k "(help)" -- rmm
169
170compctl -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
174
175compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' \
176  -k "(alias check draft draftfolder draftmessage help nocheck \
177  nodraftfolder)" -- whom
178
179compctl -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
186
187compctl -K mhfseq -x 's[+][@]' -K mhcomp -S / -q - 's[-]' -k '(help)' -- mhpath
188
Note: See TracBrowser for help on using the repository browser.