From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2162 invoked from network); 10 Mar 2003 15:03:39 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 10 Mar 2003 15:03:39 -0000 Received: (qmail 23655 invoked by alias); 10 Mar 2003 15:03:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18331 Received: (qmail 23648 invoked from network); 10 Mar 2003 15:03:30 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 10 Mar 2003 15:03:30 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [212.125.75.4] by sunsite.dk (MessageWall 1.0.8) with SMTP; 10 Mar 2003 15:3:29 -0000 Received: (qmail 20290 invoked from network); 10 Mar 2003 15:03:28 -0000 Received: from iris.logica.co.uk (158.234.9.163) by server-19.tower-1.messagelabs.com with SMTP; 10 Mar 2003 15:03:28 -0000 Received: from finches.logica.co.uk ([158.234.142.11]) by iris.logica.co.uk (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id PAA16070 for ; Mon, 10 Mar 2003 15:03:27 GMT X-Authentication-Warning: iris.logica.co.uk: Host [158.234.142.11] claimed to be finches.logica.co.uk Received: from finches.logica.co.uk (localhost [127.0.0.1]) by finches.logica.co.uk (8.11.6/8.11.6/SuSE Linux 0.5) with ESMTP id h2AF7P803279 for ; Mon, 10 Mar 2003 16:07:25 +0100 To: zsh-workers@sunsite.dk X-VirusChecked: Checked In-reply-to: <1030308213038.ZM14501@candle.brasslantern.com> From: Oliver Kiddle References: <1030308213038.ZM14501@candle.brasslantern.com> Subject: Re: Quelling default completions for homonymous commands Date: Mon, 10 Mar 2003 16:07:25 +0100 Message-ID: <3277.1047308845@finches.logica.co.uk> 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