zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: _netcat
@ 2002-03-10 22:25 Bart Schaefer
  2002-03-11 11:26 ` Oliver Kiddle
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2002-03-10 22:25 UTC (permalink / raw)
  To: zsh-workers

} nc conflicts with _nedit.  On Debian this isn't an issue
} (nedit's nc is distributed as nedit-nc), so the compdef
} line in _nedit can be changed accordingly.
} 
} Elsewhere, I can't think of a good solution.

The one thing we *can't* do is leave `#compdef nc' in *both* of them, as
has been the case since you checked in _netcat.  If it's in both of them,
the one that is chosen for `nc' will vary depending on whether zsh was
configured with --enable-function-subdirs.

What if we were to create a new Completion/X/Command/_nc that contains:

#compdef -p *X*/nc
_nedit "$@"

This would mean that if the `nc' found first in the user's path were under
a directory with `X' in its name, it would complete as if for _nedit, else
it will use the `nc' compdef from _netcat.

Then we'd change the #compdef in _nedit to read

#compdef nedit nedit-nc

or whatever is appropriate.

Anybody foresee problems with this?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: _netcat
  2002-03-10 22:25 PATCH: _netcat Bart Schaefer
@ 2002-03-11 11:26 ` Oliver Kiddle
  2002-03-12 17:38   ` Oliver Kiddle
  0 siblings, 1 reply; 10+ messages in thread
From: Oliver Kiddle @ 2002-03-11 11:26 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Sun, Mar 10, 2002 at 10:25:51PM +0000, Bart Schaefer wrote:
> } nc conflicts with _nedit.  On Debian this isn't an issue
> } (nedit's nc is distributed as nedit-nc), so the compdef
> } line in _nedit can be changed accordingly.

Argh. I knew this would happen sooner or later and was hoping nobody
would write an _netcat.

> The one thing we *can't* do is leave `#compdef nc' in *both* of them, as

Agreed.

> #compdef -p *X*/nc
> _nedit "$@"

I don't really like that. I tend to have nc in ~/bin or /usr/local
because distributions tend to link nedit against lesstif instead of real
motif and because I often have newer versions out of cvs.
Admittedly, I can work around it with a compdef in my .zshrc but I don't
like that.

What I would suggest is that we use something like the is_gnu tests in
_netcat which runs nc -h and looks for something like *connect*.
_netcat can then call _nedit if appropriate.

I also think it would be pertinent to rename _is_gnu to something like
_cmd_variant and use the value gnu instead of yes. Does that sound
reasonable?

> Then we'd change the #compdef in _nedit to read
> 
> #compdef nedit nedit-nc

Mandrake uses ncl. If anyone has SuSE, could they please check what it
does. I'm fairly unsure but I think they used `netcat' for netcat.
Certainly, I don't remember having problems with the name clash when I
used it.

I'll also check what is going on in the latest nedit cvs because a few
months ago there was a discussion about renaming nc to nedit and nedit
to nedit-server or of making the main nedit program act as a server by
default.

Oliver

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.


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

* Re: PATCH: _netcat
  2002-03-11 11:26 ` Oliver Kiddle
@ 2002-03-12 17:38   ` Oliver Kiddle
  2002-03-13  8:32     ` Sven Wischnowsky
  0 siblings, 1 reply; 10+ messages in thread
From: Oliver Kiddle @ 2002-03-12 17:38 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Bart Schaefer, zsh-workers

I wrote:
> 
> What I would suggest is that we use something like the is_gnu tests in
> _netcat which runs nc -h and looks for something like *connect*.
> _netcat can then call _nedit if appropriate.
> 
> I also think it would be pertinent to rename _is_gnu to something like
> _cmd_variant and use the value gnu instead of yes. Does that sound
> reasonable?

Below is a suggested patch which I won't commit without a positive
reponse first. Any alternate suggestions to the parameter name
_cmd_variant and the tag name variant particularly welcome. Is it unwise
to change the existing use of the tag `version' - I'd be suprised
if anyone has configured this in a style.

I've changed _iconv for an example of how I think the renaming of
_is_gnu should look like. An alternative to this would be to ditch
_cmd_variant and get _netcat to just do _comps[nc]=_nedit.

Oliver

Index: Completion/Unix/Command/_iconv
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_iconv,v
retrieving revision 1.1
diff -u -r1.1 _iconv
--- Completion/Unix/Command/_iconv	2 Apr 2001 11:53:06 -0000	1.1
+++ Completion/Unix/Command/_iconv	12 Mar 2002 17:27:57 -0000
@@ -2,17 +2,17 @@
 
 local expl curcontext="$curcontext" state line codeset LOCPATH
 
-(( $+_is_gnu )) || typeset -gA _is_gnu
-if (( ! $+_is_gnu[$words[1]] )); then
-  if [[ $(_call_program version $words[1] --version </dev/null 2>/dev/null) = *GNU* ]]; 
+(( $+_cmd_variant )) || typeset -gA _cmd_variant
+if (( ! $+_cmd_variant[$words[1]] )); then
+  if [[ $(_call_program variant $words[1] --version </dev/null 2>/dev/null) = *GNU* ]]; 
   then
-    _is_gnu[$words[1]]=yes
+    _cmd_variant[$words[1]]=gnu
   else
-    _is_gnu[$words[1]]=
+    _cmd_variant[$words[1]]=
   fi
 fi
 
-if [[ -n "$_is_gnu[$words[1]]" ]]; then
+if [[ -n "$_cmd_variant[$words[1]]" ]]; then
 
   _arguments -C \
     {'(--from-code --list)-f','(-f --list)--from-code='}'[specify code set of input file]:code set:->codeset' \
Index: Completion/Unix/Command/_netcat
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_netcat,v
retrieving revision 1.1
diff -u -r1.1 _netcat
--- Completion/Unix/Command/_netcat	10 Mar 2002 04:20:56 -0000	1.1
+++ Completion/Unix/Command/_netcat	12 Mar 2002 17:27:57 -0000
@@ -3,6 +3,20 @@
 local curcontext="$curcontext" state line expl
 typeset -A opt_args
 
+# handle name clash with the nedit client
+if [[ $service = nc ]]; then
+  (( $+_cmd_variant )) || typeset -gA _cmd_variant
+  if (( ! $+_cmd_variant[$words[1]] )); then
+    if [[ $(_call_program variant $words[1] -h </dev/null 2>/dev/null) = *connect* ]]; 
+    then
+      _cmd_variant[$words[1]]=netcat
+    else
+      _cmd_variant[$words[1]]=nedit
+    fi
+  fi
+  [[ $_cmd_variant[$words[1]] = nedit ]] && _nedit
+fi
+
 if (( ! $+_nc_args )); then
   local help="$(_call_program options nc -h < /dev/null 2>&1)"
   local -A optionmap
Index: Completion/X/Command/_nedit
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/Command/_nedit,v
retrieving revision 1.1
diff -u -r1.1 _nedit
--- Completion/X/Command/_nedit	2 Apr 2001 12:14:08 -0000	1.1
+++ Completion/X/Command/_nedit	12 Mar 2002 17:27:58 -0000
@@ -1,4 +1,4 @@
-#compdef nedit nc
+#compdef nedit nedit-nc=nc ncl=nc
 
 local state line expl nedit_common curcontext="$curcontext" ret=1
 typeset -A opt_args

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.


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

* Re: PATCH: _netcat
  2002-03-12 17:38   ` Oliver Kiddle
@ 2002-03-13  8:32     ` Sven Wischnowsky
  2002-03-14 12:22       ` Oliver Kiddle
  0 siblings, 1 reply; 10+ messages in thread
From: Sven Wischnowsky @ 2002-03-13  8:32 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> ...
> 
> Below is a suggested patch which I won't commit without a positive
> reponse first. Any alternate suggestions to the parameter name
> _cmd_variant and the tag name variant particularly welcome. Is it unwise
> to change the existing use of the tag `version' - I'd be suprised
> if anyone has configured this in a style.

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.

> ...
>  
>  local expl curcontext="$curcontext" state line codeset LOCPATH
>  
> -(( $+_is_gnu )) || typeset -gA _is_gnu
> -if (( ! $+_is_gnu[$words[1]] )); then
> -  if [[ $(_call_program version $words[1] --version </dev/null 2>/dev/null) = *GNU* ]]; 
> +(( $+_cmd_variant )) || typeset -gA _cmd_variant
> +if (( ! $+_cmd_variant[$words[1]] )); then
> +  if [[ $(_call_program variant $words[1] --version </dev/null 2>/dev/null) = *GNU* ]]; 
>    then
> -    _is_gnu[$words[1]]=yes
> +    _cmd_variant[$words[1]]=gnu
>    else
> -    _is_gnu[$words[1]]=
> +    _cmd_variant[$words[1]]=
>    fi
>  fi

Hm, some kind of helper-function for this?

> -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'?
As you do in:

> ...
> +  [[ $_cmd_variant[$words[1]] = nedit ]] && _nedit


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?)


Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@berkom.de


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

* Re: PATCH: _netcat
  2002-03-13  8:32     ` Sven Wischnowsky
@ 2002-03-14 12:22       ` Oliver Kiddle
  2002-03-15  8:39         ` Sven Wischnowsky
  0 siblings, 1 reply; 10+ messages in thread
From: Oliver Kiddle @ 2002-03-14 12:22 UTC (permalink / raw)
  To: zsh-workers

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.


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

* Re: PATCH: _netcat
  2002-03-14 12:22       ` Oliver Kiddle
@ 2002-03-15  8:39         ` Sven Wischnowsky
  2002-03-15 16:06           ` Oliver Kiddle
  0 siblings, 1 reply; 10+ messages in thread
From: Sven Wischnowsky @ 2002-03-15  8:39 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> ...
> 
> How about the following. Usage is, for example:
>    _pick_variant netcat=connect nedit -h
> or _pick_variant -c diff gnu=GNU unix --version

The only thing I would suggest is that it (optionally?) gets a
parameter name as argument into which the command variant is stored so
that the calling function doesn't have to do the lookup itself (yes,
only a little easier, but...).

Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@berkom.de


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

* Re: PATCH: _netcat
  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
  0 siblings, 2 replies; 10+ messages in thread
From: Oliver Kiddle @ 2002-03-15 16:06 UTC (permalink / raw)
  To: zsh-workers

On Fri, Mar 15, 2002 at 09:39:49AM +0100, Sven Wischnowsky wrote:
> 
> The only thing I would suggest is that it (optionally?) gets a
> parameter name as argument into which the command variant is stored so
> that the calling function doesn't have to do the lookup itself (yes,
> only a little easier, but...).

Okay. I've added a -r option for that. Following patch includes all the
old _is_gnu using functions and documentation. I'll commit it now to get
it out of my way but can always change it next week. The -r was useful
in a couple of places but mostly I've used the return code.

One point about zparseopts -K with an association though. With opts[-c]
set before zparseopts and a -r option passed to _pick_variant, it
loses the value of opts[-c]. This came up with _make and I solved it
by not using -K. I suspect that it is applying -K across the whole
association instead of per-element as I would have expected.

Oliver

Index: Completion/Base/Utility/.distfiles
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/.distfiles,v
retrieving revision 1.3
diff -u -r1.3 .distfiles
--- Completion/Base/Utility/.distfiles	5 Mar 2002 18:34:19 -0000	1.3
+++ Completion/Base/Utility/.distfiles	15 Mar 2002 16:04:33 -0000
@@ -3,6 +3,6 @@
 _alternative      _call_program     _nothing          _sub_commands
 _arg_compile      _combination      _regex_arguments  _values
 _arguments        _set_command      _retrieve_cache   _guard
-_cache_invalid    _describe         _sep_parts
+_cache_invalid    _describe         _sep_parts        _pick_variant
 _call_function    _multi_parts      _store_cache
 '
Index: Completion/Unix/Command/_cpio
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_cpio,v
retrieving revision 1.2
diff -u -r1.2 _cpio
--- Completion/Unix/Command/_cpio	16 Jan 2002 16:29:52 -0000	1.2
+++ Completion/Unix/Command/_cpio	15 Mar 2002 16:04:33 -0000
@@ -1,33 +1,23 @@
 #compdef cpio
 
-(( $+_is_gnu )) || typeset -gA _is_gnu
-
-local cmd=$service args ig curcontext="$curcontext" state line
+local args ig curcontext="$curcontext" state line
 local expl ret
 local fmts='(bar bin odc newc crc tar ustar hpbin hpodc)'
 
-if (( ! $+_is_gnu[$cmd] )); then
-  if [[ $(_call_program version $cmd --version </dev/null 2>/dev/null) = *GNU* ]]
-  then
-    _is_gnu[$cmd]=yes
-  else
-    _is_gnu[$cmd]=
-  fi
-fi 
-ig=$_is_gnu[$cmd]
+_pick_variant -r ig gnu=GNU unix --version
 
-if (( $CURRENT == 2 )); then
+if (( CURRENT == 2 )); then
    # Complete arguments 
    args=('-o[create archive]' '-i[extract from archive]'
    '-p[run as filter on directory tree]')
-   [[ -n $ig ]] && args=($args '--create[create archive]'
+   [[ $ig = gnu ]] && args=($args '--create[create archive]'
    '--extract[extract from archive]' 
    '--pass-through[run as filter on directory tree]'
    '--help[show help text]' '--version[show version information]')
 else
   if [[ -n ${words[(r)(-o*|-[^-]*o*|--create)]} ]]; then
-    # Optiona for creating archive
-    if [[ -n $ig ]]; then
+    # Options for creating archive
+    if [[ $ig = gnu ]]; then
 	args=(
 	   '--file=:archive file:->afile'
 	   "--format=:format type:$fmts"
@@ -51,7 +41,7 @@
 	  '-O[set output archive file]:output archive file:_files'
 	 )
   elif [[ -n ${words[(r)(-i*|-[^-]*i*|--extract)]} ]]; then
-    if [[ -n $ig ]]; then
+    if [[ $ig = gnu ]]; then
       args=('--file=:archive file:->afile'
 	    "--format=:format type:$fmts"
 	    '--make-directories' '--nonmatching' 
@@ -90,7 +80,7 @@
 	  '*:pattern to extract'
 	  )
   elif [[ -n ${words[(r)(-p*|-[^-]*p*|--pass-through)]} ]]; then
-    if [[ -n $ig ]]; then
+    if [[ $ig = gnu ]]; then
       args=('--null' '--reset-access-time' '--make-directories'
             '--link' '--quiet' '--preserve-modification-time'
 	    '--unconditional' '--verbose' '--dot' '--dereference'
Index: Completion/Unix/Command/_grep
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_grep,v
retrieving revision 1.5
diff -u -r1.5 _grep
--- Completion/Unix/Command/_grep	15 Mar 2002 14:49:39 -0000	1.5
+++ Completion/Unix/Command/_grep	15 Mar 2002 16:04:33 -0000
@@ -16,17 +16,6 @@
   command="$words[1]"
 fi
 
-(( $+_is_gnu )) || typeset -gA _is_gnu
-
-if (( ! $+_is_gnu[$command] )); then
-  if [[ $(_call_program version $command --help </dev/null 2>/dev/null) = *gnu* ]]
-  then
-    _is_gnu[$command]=yes
-  else
-    _is_gnu[$command]=
-  fi
-fi
-
 if [[ $service != [ef]grep ]]; then
   matchers='(--extended-regexp --fixed-strings --basic-regexp --perl-regexp -E -F -G -P)'
   arguments+=(
@@ -77,7 +66,7 @@
 )
 
 # remove long options?
-[[ -z "$_is_gnu[$command]" ]] &&
+_pick_variant -c "$command" gnu=gnu unix --help ||
     arguments=( ${arguments:#(|*\)(\*|))--*} )
 
 _arguments -s $arguments[@]
Index: Completion/Unix/Command/_iconv
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_iconv,v
retrieving revision 1.1
diff -u -r1.1 _iconv
--- Completion/Unix/Command/_iconv	2 Apr 2001 11:53:06 -0000	1.1
+++ Completion/Unix/Command/_iconv	15 Mar 2002 16:04:33 -0000
@@ -2,17 +2,7 @@
 
 local expl curcontext="$curcontext" state line codeset LOCPATH
 
-(( $+_is_gnu )) || typeset -gA _is_gnu
-if (( ! $+_is_gnu[$words[1]] )); then
-  if [[ $(_call_program version $words[1] --version </dev/null 2>/dev/null) = *GNU* ]]; 
-  then
-    _is_gnu[$words[1]]=yes
-  else
-    _is_gnu[$words[1]]=
-  fi
-fi
-
-if [[ -n "$_is_gnu[$words[1]]" ]]; then
+if _pick_variant gnu=GNU unix --version; then
 
   _arguments -C \
     {'(--from-code --list)-f','(-f --list)--from-code='}'[specify code set of input file]:code set:->codeset' \
Index: Completion/Unix/Command/_ls
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_ls,v
retrieving revision 1.3
diff -u -r1.3 _ls
--- Completion/Unix/Command/_ls	6 Aug 2001 14:42:04 -0000	1.3
+++ Completion/Unix/Command/_ls	15 Mar 2002 16:04:33 -0000
@@ -3,17 +3,6 @@
 
 local arguments
 
-(( $+_is_gnu )) || typeset -gA _is_gnu
-
-if (( ! $+_is_gnu[$words[1]] )); then
-  if [[ $(_call_program version $words[1] --help </dev/null 2>/dev/null) = *gnu* ]]
-  then
-    _is_gnu[$words[1]]=yes
-  else
-    _is_gnu[$words[1]]=
-  fi
-fi
-
 arguments=(
   '(--all -a -A --almost-all)'{--all,-a}'[list entries starting with .]'
   '(--almost-all -A -a --all)'{--almost-all,-A}'[list all except . and ..]'
@@ -79,7 +68,7 @@
 )
 
 # remove long options?
-[[ -z "$_is_gnu[$words[1]]" ]] &&
+_pick_variant gnu=gnu unix --help ||
     arguments=( ${${${arguments:#(|*\))--*}//--[^ )]#/}/\( #\)/} )
 
 _arguments -s $arguments
Index: Completion/Unix/Command/_make
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_make,v
retrieving revision 1.2
diff -u -r1.2 _make
--- Completion/Unix/Command/_make	13 Mar 2002 09:28:05 -0000	1.2
+++ Completion/Unix/Command/_make	15 Mar 2002 16:04:33 -0000
@@ -1,17 +1,8 @@
 #compdef make gmake pmake dmake
 
-local prev="$words[CURRENT-1]" file expl tmp
+local prev="$words[CURRENT-1]" file expl tmp is_gnu
 
-(( $+_is_gnu )) || typeset -gA _is_gnu
-
-if (( ! $+_is_gnu[$words[1]] )); then
-  if [[ $(_call_program version $words[1] -v -f /dev/null </dev/null 2>/dev/null) = *GNU* ]]
-  then
-    _is_gnu[$words[1]]=yes
-  else
-    _is_gnu[$words[1]]=
-  fi
-fi
+_pick_variant -r is_gnu gnu=GNU unix -v -f
 
 if [[ "$prev" = -[CI] ]]; then
   _files -/
@@ -25,14 +16,14 @@
     file=Makefile
   elif [[ -e makefile ]]; then
     file=makefile
-  elif [[ -n "$_is_gnu[$words[1]]" && -e GNUmakefile ]]; then
+  elif [[ $is_gnu = gnu && -e GNUmakefile ]]; then
     file=GNUmakefile
   else
     file=''
   fi
 
   if [[ -n "$file" ]] && _tags targets; then
-    if [[ -n "$_is_gnu[$words[1]]" ]] &&
+    if [[ $is_gnu = gnu ]] &&
        zstyle -t ":completion:${curcontext}:targets" call-command; then
       tmp=( $(_call_program targets "$words[1]" -nsp --no-print-directory -f "$file" .PHONY 2> /dev/null | awk '/^[a-zA-Z0-9][^\/\t=]+:/ {print $1}' FS=:) )
     else
Index: Completion/Unix/Command/_netcat
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_netcat,v
retrieving revision 1.1
diff -u -r1.1 _netcat
--- Completion/Unix/Command/_netcat	10 Mar 2002 04:20:56 -0000	1.1
+++ Completion/Unix/Command/_netcat	15 Mar 2002 16:04:33 -0000
@@ -3,6 +3,10 @@
 local curcontext="$curcontext" state line expl
 typeset -A opt_args
 
+# handle name clash with the nedit client
+[[ $service = nc ]] && ! _pick_variant netcat=connect nedit -h &&
+    _nedit && return
+
 if (( ! $+_nc_args )); then
   local help="$(_call_program options nc -h < /dev/null 2>&1)"
   local -A optionmap
Index: Completion/Unix/Command/_zcat
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_zcat,v
retrieving revision 1.1
diff -u -r1.1 _zcat
--- Completion/Unix/Command/_zcat	2 Apr 2001 12:07:09 -0000	1.1
+++ Completion/Unix/Command/_zcat	15 Mar 2002 16:04:33 -0000
@@ -1,18 +1,6 @@
 #compdef zcat
 
-(( $+_is_gnu )) || typeset -gA _is_gnu
-
-if (( ! $+_is_gnu[$words[1]] )); then
-  if [[ $(_call_program version $words[1] --license </dev/null 2>&1) = *GNU* ]]
-  then
-    _is_gnu[$words[1]]=yes
-  else
-    _is_gnu[$words[1]]=
-  fi
-fi
-
-if [[ -n "$_is_gnu[$words[1]]" ]]
-then
+if _pick_variant gnu=GNU unix --license; then
   _gzip "$@"
 else
   _compress "$@"
Index: Completion/Unix/Type/_diff_options
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_diff_options,v
retrieving revision 1.3
diff -u -r1.3 _diff_options
--- Completion/Unix/Type/_diff_options	6 Aug 2001 14:42:04 -0000	1.3
+++ Completion/Unix/Type/_diff_options	15 Mar 2002 16:04:33 -0000
@@ -2,20 +2,10 @@
 
 local of ofwuc ouc oss ofwy ofwg ofwl cmd
 
-(( $+_is_gnu )) || typeset -gA _is_gnu
-
 cmd="$1"
 shift
 
-if (( ! $+_is_gnu[$cmd] )); then
-  if [[ $(_call_program version $cmd -v </dev/null 2>/dev/null) = *GNU* ]]; then
-    _is_gnu[$cmd]=yes
-  else
-    _is_gnu[$cmd]=
-  fi
-fi
-
-if [[ -n "$_is_gnu[$cmd]" ]]; then
+if _pick_variant -c $cmd gnu=GNU unix -v; then
   # output formats
   of="-y --side-by-side -n --rcs -e -f --ed -q --brief -c -C --context -u -U \
   --unified --old-group-format --new-group-format --changed-group-format \
Index: Completion/X/Command/_nedit
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/Command/_nedit,v
retrieving revision 1.1
diff -u -r1.1 _nedit
--- Completion/X/Command/_nedit	2 Apr 2001 12:14:08 -0000	1.1
+++ Completion/X/Command/_nedit	15 Mar 2002 16:04:33 -0000
@@ -1,4 +1,4 @@
-#compdef nedit nc
+#compdef nedit nedit-nc=nc ncl=nc
 
 local state line expl nedit_common curcontext="$curcontext" ret=1
 typeset -A opt_args
@@ -14,7 +14,7 @@
   '*-xrm:resource:_x_resource' \
   '*:file:_files' )
 
-if [[ $service = *nc ]]; then
+if [[ $service = nc ]]; then
   _x_arguments -C \
     '(-noask)-ask[prompt if no server found]' \
     '(-ask)-noask[start a new server without asking if none found]' \
Index: Completion/Zsh/Command/_zstyle
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_zstyle,v
retrieving revision 1.7
diff -u -r1.7 _zstyle
--- Completion/Zsh/Command/_zstyle	17 Jan 2002 18:49:36 -0000	1.7
+++ Completion/Zsh/Command/_zstyle	15 Mar 2002 16:04:33 -0000
@@ -141,7 +141,7 @@
   other-accounts packages parameters path-directories paths pods ports
   prefixes printers processes processes-names ps regex sequences
   sessions signals strings styles tags targets timezones types urls
-  users values version visuals warnings widgets windows zsh-options
+  users values variant visuals warnings widgets windows zsh-options
 )
 
 _arguments -C \
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.148
diff -u -r1.148 compsys.yo
--- Doc/Zsh/compsys.yo	13 Mar 2002 09:28:05 -0000	1.148
+++ Doc/Zsh/compsys.yo	15 Mar 2002 16:04:33 -0000
@@ -864,10 +864,10 @@
 when completing a value out of a set of values (or a list of such
 values)
 )
-kindex(version, completion tag)
-item(tt(version))(
-used by tt(_call_program) to look up the command to run to determine the installed
-version of various other commands (such as tt(diff) and tt(make)).
+kindex(variant, completion tag)
+item(tt(variant))(
+used by tt(_pick_variant) to look up the command to run when determining
+what program is installed for a particular command name.
 )
 kindex(visuals, completion tag)
 item(tt(visuals))(
@@ -3941,6 +3941,26 @@
 
 Finally, the tt(_path_files) function  uses the styles tt(expand),
 tt(ambiguous), tt(special-dirs), tt(list-suffixes) and tt(file-sort).
+)
+findex(_pick_variant)
+item(tt(_pick_variant [ tt(-c) var(command) ] [ tt(-r) var(name) ] var(command)tt(=)var(pattern) ... var(command) [ var(args ... ]))(
+This function is used to resolve situations where a command has more
+than one variant, each requiring different handling or where there is a
+name clash between two different commands.
+
+_pick_variant does this by running the command and comparing its output
+against a series of patterns. The command to run is taken from the
+first element of the var(words) array unless specified with the tt(-c)
+option. Arguments to be passed on to it can be specified at the end
+after all the other arguments. The patterns are specified by the series
+of var(command)tt(=)var(pattern) arguments where var(command) is a
+label used to describe each command. If none of the patterns match, the
+final command label is taken and 1 is returned.
+
+The results are cached in the var(_cmd_variant) associative array so
+the calling function can either look up the result in there or it can
+pass the name of a parameter with the tt(-r) option which will be set
+to the result.
 )
 findex(_regex_arguments)
 item(tt(_regex_arguments) var(name) var(specs) ...)(

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.


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

* Re: PATCH: _netcat
  2002-03-15 16:06           ` Oliver Kiddle
@ 2002-03-15 16:45             ` Bart Schaefer
  2002-03-20  9:23             ` Sven Wischnowsky
  1 sibling, 0 replies; 10+ messages in thread
From: Bart Schaefer @ 2002-03-15 16:45 UTC (permalink / raw)
  To: zsh-workers

On Mar 15,  4:06pm, Oliver Kiddle wrote:
}
} One point about zparseopts -K with an association though. With opts[-c]
} set before zparseopts and a -r option passed to _pick_variant, it
} loses the value of opts[-c]. This came up with _make and I solved it
} by not using -K. I suspect that it is applying -K across the whole
} association instead of per-element as I would have expected.

You can't make individual elements of an association `local', so I'm not
sure why you expected `zparseopts -K' to behave any differently; but I'm
still not sure I understand what actually happened.


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

* Re: PATCH: _netcat
  2002-03-15 16:06           ` Oliver Kiddle
  2002-03-15 16:45             ` Bart Schaefer
@ 2002-03-20  9:23             ` Sven Wischnowsky
  1 sibling, 0 replies; 10+ messages in thread
From: Sven Wischnowsky @ 2002-03-20  9:23 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> ...
> 
> One point about zparseopts -K with an association though. With opts[-c]
> set before zparseopts and a -r option passed to _pick_variant, it
> loses the value of opts[-c]. This came up with _make and I solved it
> by not using -K. I suspect that it is applying -K across the whole
> association instead of per-element as I would have expected.

That's right, it just calls sethparam().  Maybe adding support for
such merging functions is another point for our list of things to do
to the parameter code.


Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@berkom.de


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

* PATCH: _netcat
@ 2002-03-10  4:17 Clint Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Clint Adams @ 2002-03-10  4:17 UTC (permalink / raw)
  To: zsh-workers

This is from Matt Zimmerman.  He points out that
nc conflicts with _nedit.  On Debian this isn't an issue
(nedit's nc is distributed as nedit-nc), so the compdef
line in _nedit can be changed accordingly.

Elsewhere, I can't think of a good solution.

Index: Completion/Unix/Command/_netcat
===================================================================
RCS file: Completion/Unix/Command/_netcat
diff -N Completion/Unix/Command/_netcat
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Unix/Command/_netcat	10 Mar 2002 04:10:50 -0000
@@ -0,0 +1,34 @@
+#compdef nc netcat
+
+local curcontext="$curcontext" state line expl
+typeset -A opt_args
+
+if (( ! $+_nc_args )); then
+  local help="$(_call_program options nc -h < /dev/null 2>&1)"
+  local -A optionmap
+  optionmap=(
+    '*-e prog*' '-e+[program to exec after connect]:prog:_command_names -e'
+     '*-g gateway*' '-g+[source-routing hop point]:gateway:_hosts'
+     '*-G num*' '-G[source-routing pointer: 4, 8, 12]'
+     '*-i secs*' '-i+[delay interval for lines sent or ports scanned]:secs:'
+     '*-l*' '-l[listen mode]'
+     '*-n*' '-n[numeric-only IP addresses, no DNS]'
+     '*-o file*' '-o+[hex dump of traffic]:file:_files'
+     '*-p port*' '-p+[local port number]:port:_ports'
+     '*-r*' '-r[randomize local and remote ports]'
+     '*-q secs*' '-q+[quit after EOF on stdin and delay of secs]:secs:'
+     '*-t*' '-t[answer TELNET negotiation]'
+     '*-u*' '-u[UDP mode]'
+     '*-v*' '-v[verbose]'
+     '*-w secs*' '-w+[timeout for connects and final net reads]:secs:'
+     '*-z*' '-z[zero-I/O mode]'
+     '*-x*' '-x'
+     '*-b*' '-b[allow broadcasts]'
+  )
+  _nc_args=($optionmap[(K)"$help"])
+fi
+
+_arguments -C -s \
+  "$_nc_args[@]" \
+  ':host:_hosts' \
+  ':port:_ports' && return 0


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

end of thread, other threads:[~2002-03-20  9:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-10 22:25 PATCH: _netcat 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
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

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).