about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2005-05-30 09:48:50 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2005-05-30 09:48:50 +0000
commit4e694103e3776c4b79946a7755e6ca823b89cd14 (patch)
treefba03e0b8f69c9f7a07097cec434b9cf8aa906b8
parent887cbbdbed140808f0ec0faf5f7e7ecd4eccb7af (diff)
downloadzsh-4e694103e3776c4b79946a7755e6ca823b89cd14.tar.gz
zsh-4e694103e3776c4b79946a7755e6ca823b89cd14.tar.xz
zsh-4e694103e3776c4b79946a7755e6ca823b89cd14.zip
21266: improve completion of sequences
-rw-r--r--ChangeLog4
-rw-r--r--Completion/Unix/Command/_mh97
2 files changed, 101 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index c4e44dc10..993d8eecd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-05-30  Oliver Kiddle  <opk@zsh.org>
+
+	* 21266: Completion/Unix/Command/_mh: improve completion of sequences
+
 2005-05-23  Peter Stephenson  <pws@csr.com>
 
 	* 21270: Src/system.h: don't use poll() on Apple.
diff --git a/Completion/Unix/Command/_mh b/Completion/Unix/Command/_mh
new file mode 100644
index 000000000..5a9348069
--- /dev/null
+++ b/Completion/Unix/Command/_mh
@@ -0,0 +1,97 @@
+#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
+
+# Completion for all possible MH commands.
+local mymhdir=${$(_call_program mhpath mhpath + 2>/dev/null):-~/Mail}
+local mhlib=/usr/lib/mh
+
+local prev="$words[CURRENT-1]" expl
+
+if compset -P 1 -; then
+  # get list of options, which MH commands can generate themselves
+  # awk is just too icky to use for this, sorry.  send me one if
+  # you come up with it.
+  local -a options disp
+  options=(
+    $($words[1] -help | perl -ne 'if (/^\s*-\(?(\S+)/) {
+       $n = $1;
+       $n =~ s/\)//g;
+       print $n =~ s/^\[([a-z]+)\]// ? "$n\n$1$n\n" : "$n\n";
+    }')
+  )
+  if zstyle -t ":completion:${curcontext}:options" prefix-hidden; then
+    _wanted options expl option compadd -d disp - "$options[@]"
+  else
+    disp=( -${options} )
+    _wanted options expl option compadd -d disp - "$options[@]"
+  fi    
+  return
+elif compset -P 1 '[+@]' || [[ "$prev" = -draftfolder ]]; then
+  # Complete folder names.
+  local mhpath
+
+  if [[ $IPREFIX != '@' ]]; then
+    [[ $IPREFIX = '+' ]] || IPREFIX=+
+    mhpath=$mymhdir
+  else
+    mhpath=$(mhpath)
+  fi
+
+  _wanted files expl 'MH folder' _path_files -W mhpath -/
+elif [[ "$prev" = -(editor|(whatnow|rmm|show|more)proc) ]]; then
+  _command_names -e
+elif [[ "$prev" = -file ]]; then
+  _files
+elif [[ "$prev" = -(form|audit|filter) ]]; then
+  # Need some MH template file, which may be in our own MH directory
+  # or with the standard library.
+  local mhfpath
+  # This is the only place we need mhlib, so leave the test till here.
+  mhlib=${${$(mhparam mhlproc 2>/dev/null):h}:-/usr/lib/mh}
+  mhfpath=($mymhdir $mhlib)
+
+  _wanted files expl 'MH template file' _files -W mhfpath -g '*(-.)'
+elif [[ $service = mhmail ]]; then
+  _email_addresses
+elif [[ "$prev" = -(no|)cc ]]; then
+  _wanted -C "$prev" values expl 'CC address' compadd all to cc me
+elif [[ "$prev" = -[rw]cache ]]; then
+  _wanted -C "$prev" values expl cache compadd public private never ask
+elif [[ $service = mhparam ]]; then
+  _wanted parameters expl 'MH parameter' compadd - \
+    ${${(f)"$(mhparam -all)"}%%:*}
+elif [[ $service = ali ]]; then
+  _email_addresses -n MH
+elif compset -P '*:'; then
+  _message -e number 'number of messages'
+else
+  # Generate sequences.
+  local foldnam folddir f sequences mhneg ret=1
+
+  compset -P '*-' # ignore start of message range
+
+  for f in $words; do
+    [[ $f = [@+]* ]] && foldnam=$f
+  done
+  if [[ $foldnam = '+'* ]]; then
+    folddir=$mymhdir/${foldnam#+}
+  elif [[ $foldnam = '@'* ]]; then
+    folddir=$(mhpath)/${foldnam#@}
+  else
+    folddir=$(mhpath)
+    # leaving foldnam empty works here
+  fi
+
+  sequences=( ${${(f)"$(mark $foldnam 2>/dev/null)"}%%:*} )
+  mhneg="$(mhparam Sequence-Negation)" && sequences=( {,$mhneg}$^sequences )
+  sequences+=( all first last prev next )
+  _tags sequences
+  while _tags; do
+    while _next_label sequences expl sequence; do
+      compadd -S ' ' -r '-: \t\n\-' "$expl[@]" -a sequences && ret=0
+      _path_files -S ' ' -r '-: \t\n\-' "$expl[@]" -W folddir -g '<->(-.)' &&
+          ret=0
+    done
+    (( ret )) || return 0
+  done
+  return ret
+fi