zsh-workers
 help / color / mirror / code / Atom feed
* Quelling default completions for homonymous commands
@ 2003-03-08 21:30 Bart Schaefer
  2003-03-10 15:07 ` Oliver Kiddle
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2003-03-08 21:30 UTC (permalink / raw)
  To: zsh-workers

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
rather skip the MH completion attempt entirely.

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.

Thoughts?


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Quelling default completions for homonymous commands
  2003-03-08 21:30 Quelling default completions for homonymous commands Bart Schaefer
@ 2003-03-10 15:07 ` Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2003-03-10 15:07 UTC (permalink / raw)
  To: zsh-workers

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.

Oliver

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    
   return
 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
 else
   # Generate sequences.
   local foldnam folddir f ret


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-03-10 15:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-08 21:30 Quelling default completions for homonymous commands Bart Schaefer
2003-03-10 15:07 ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).