From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2230 invoked from network); 14 Mar 2002 12:22:39 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 14 Mar 2002 12:22:39 -0000 Received: (qmail 23815 invoked by alias); 14 Mar 2002 12:22:32 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16830 Received: (qmail 23801 invoked from network); 14 Mar 2002 12:22:32 -0000 X-VirusChecked: Checked Date: Thu, 14 Mar 2002 12:22:03 +0000 From: Oliver Kiddle To: zsh-workers@sunsite.dk Subject: Re: PATCH: _netcat Message-ID: <20020314122203.GA28294@logica.com> References: <1020310222552.ZM26165@candle.brasslantern.com> <20020311112606.GA20670@logica.com> <20020312173831.GA30789@logica.com> <15503.3721.373253.225908@wischnow.berkom.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <15503.3721.373253.225908@wischnow.berkom.de> User-Agent: Mutt/1.3.27i Sender: Oliver Kiddle Sven wrote: > 1) I like the change because it's more extensible. 2) Can't help you > with a better name, sorry. 3) I don't worry to much about the tag-name > change either. Good. Thanks. > Hm, some kind of helper-function for this? I've considered that before but wasn't sure how to make it sufficiently general. How about the following. Usage is, for example: _pick_variant netcat=connect nedit -h or _pick_variant -c diff gnu=GNU unix --version The -c option is for where $words[1] isn't to be used. Then you can have any number of command=pattern arguments (so it can differentiate more than two variants of a command). Then you have the command for if no patterns matched and then any subsequent arguments are passed as parameters to the command. Can you think of a better way of describing this information in the arguments? I've got it to return 1 if it resorts to the last choice so in most cases the function can be used with if to avoid checking $_cmd_variant in the calling function. I'm not sure whether that is a good idea though. > > -if [[ -n "$_is_gnu[$words[1]]" ]]; then > > +if [[ -n "$_cmd_variant[$words[1]]" ]]; then > > I'm confused. Shoudn't this test `"$_cmd_variant[$words[1]]" = gnu'? Yes, it should really. It was like that before - I just changed yes to gnu and _is_gnu to _cmd_variant. When it is not gnu, I'll use a different word in _cmd_variant like `no' or `unix' instead of the empty string (as it currently is). > And, btw., on this Suse-box: > > % which netcat > /usr/bin/netcat > > And nc is the nedit-thing. (You asked for this, right? OR was it > someone else?) Yes, I did ask that. Thanks. I see that _netcat already has netcat in the compdef line so we have it right as long as no other distributions have done something different about the name clash. Oliver #autoload local output command cmd pat local -a var (( $+_cmd_variant )) || typeset -gA _cmd_variant if [[ $1 = -c ]]; then command="$2" shift 2 else command="$words[1]" fi while [[ $1 = *=* ]]; do var+=( "${1%%\=*}" "${1#*=}" ) shift done if (( $+_cmd_variant[$command] )); then [[ $_cmd_variant[$command] = "$1" ]] && return 1 return 0 fi output="$(_call_program variant $command "${@[2,-1]}" /dev/null)" for cmd pat in "$var[@]"; do if [[ $output = *$~pat* ]]; then _cmd_variant[$command]="$cmd" return fi done _cmd_variant[$command]="$1" return 1 -- This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.