Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Quelling default completions for homonymous commands

Bart wrote:
> I have a shell function named "show" that I've used for years.  It has
> nothing to do with the MH command "show", but I've just noticed that zsh
> complains to stderr "_mh:1: command not found: mhpath" when I complete for
> my "show" function.
> This is foremost a bug in _mh, because completion functions should not
> invoke external commands without a strategic 2>/dev/null.  However, I'd

It had a 2>/dev/null but was lacking the use of _call_program and
command not found is output by zsh not the program.

> Obviously I can "compdef -d show" somewhere in my startup files, but I
> wonder whether there ought to be some more generalized way to avoid even
> loading the completion functions for commands that are not installed.

We could make compinit look for commands or functions with the specified
names but it couldn't easily tell the difference between your show
function and MH's show. Any user who runs compinit before setting their
path may also have problems.

If you can think of a way to do it, I can see that it would be a good
thing though.

I've added the _call_program to _mh below though it probably needs a few
more. I also added handling for more (n)MH commands, the prefix-hidden
style and use of _email_addresses.


Index: Completion/Unix/Command/_mh
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_mh,v
retrieving revision 1.1
diff -u -r1.1 _mh
--- Completion/Unix/Command/_mh	2 Apr 2001 11:57:20 -0000	1.1
+++ Completion/Unix/Command/_mh	10 Mar 2003 14:42:16 -0000
@@ -1,25 +1,30 @@
-#compdef folder folders comp inc mark refile repl scan show next prev rmm pick whom mhn mhpath mhlist mhstore mhshow mhparam mhmail
+#compdef ali dist flist flists folder folders forw comp inc mark refile repl scan show next prev packf rmf rmm pick whom mhn mhpath mhlist mhstore mhshow mhparam mhmail
 # Completion for all possible MH commands.
-local mymhdir=${$(mhpath + 2>/dev/null):-~/Mail}
+local mymhdir=${$(_call_program mhpath mhpath + 2>/dev/null):-~/Mail}
 local mhlib=/usr/lib/mh
 local prev="$words[CURRENT-1]" expl
-# To be on the safe side, check this exists and if not, get it anyway.
-[[ -d $mymhdir ]] || mymhdir=$(mhpath +)
 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.
-  _wanted options expl option \
-      compadd - $($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";
-          }')
+  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    
 elif compset -P 1 '[+@]' || [[ "$prev" = -draftfolder ]]; then
   # Complete folder names.
@@ -46,6 +51,8 @@
   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
@@ -53,8 +60,8 @@
 elif [[ $service = mhparam ]]; then
   _wanted parameters expl 'MH parameter' compadd - \
     ${${(f)"$(mhparam -all)"}%%:*}
-elif [[ $service = mhmail ]]; then
-  _user_at_host
+elif [[ $service = ali ]]; then
+  _email_addresses -n MH
   # Generate sequences.
   local foldnam folddir f ret

Messages sorted by: Reverse Date, Date, Thread, Author