From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@sunsite.dk
Subject: Re: PATCH: _netcat
Date: Thu, 14 Mar 2002 12:22:03 +0000 [thread overview]
Message-ID: <20020314122203.GA28294@logica.com> (raw)
In-Reply-To: <15503.3721.373253.225908@wischnow.berkom.de>
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 2>/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.
next prev parent reply other threads:[~2002-03-14 12:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-10 22:25 Bart Schaefer
2002-03-11 11:26 ` Oliver Kiddle
2002-03-12 17:38 ` Oliver Kiddle
2002-03-13 8:32 ` Sven Wischnowsky
2002-03-14 12:22 ` Oliver Kiddle [this message]
2002-03-15 8:39 ` Sven Wischnowsky
2002-03-15 16:06 ` Oliver Kiddle
2002-03-15 16:45 ` Bart Schaefer
2002-03-20 9:23 ` Sven Wischnowsky
-- strict thread matches above, loose matches on Subject: below --
2002-03-10 4:17 Clint Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020314122203.GA28294@logica.com \
--to=okiddle@yahoo.co.uk \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).