about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorOliver Kiddle <opk@users.sourceforge.net>2002-03-15 16:26:08 +0000
committerOliver Kiddle <opk@users.sourceforge.net>2002-03-15 16:26:08 +0000
commit79323d6d41c91860cd05800a06cf8076df5051bd (patch)
tree0c08a2486422faa6f805589f2f60f640134b455b /Completion
parent2fa33574f029358dc1597b1ff8700385d7c8332a (diff)
downloadzsh-79323d6d41c91860cd05800a06cf8076df5051bd.tar.gz
zsh-79323d6d41c91860cd05800a06cf8076df5051bd.tar.xz
zsh-79323d6d41c91860cd05800a06cf8076df5051bd.zip
16842: resolve name clash for nc between netcat and the nedit client for
completion and add _pick_variant to resolve program variants in general
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Base/Utility/.distfiles2
-rw-r--r--Completion/Base/Utility/_pick_variant35
-rw-r--r--Completion/Unix/Command/_cpio26
-rw-r--r--Completion/Unix/Command/_grep13
-rw-r--r--Completion/Unix/Command/_iconv12
-rw-r--r--Completion/Unix/Command/_ls13
-rw-r--r--Completion/Unix/Command/_make17
-rw-r--r--Completion/Unix/Command/_netcat4
-rw-r--r--Completion/Unix/Command/_zcat14
-rw-r--r--Completion/Unix/Type/_diff_options12
-rw-r--r--Completion/X/Command/_nedit4
-rw-r--r--Completion/Zsh/Command/_zstyle2
12 files changed, 60 insertions, 94 deletions
diff --git a/Completion/Base/Utility/.distfiles b/Completion/Base/Utility/.distfiles
index 30ddbac5e..de4c5ef20 100644
--- a/Completion/Base/Utility/.distfiles
+++ b/Completion/Base/Utility/.distfiles
@@ -3,6 +3,6 @@ DISTFILES_SRC='
 _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
 '
diff --git a/Completion/Base/Utility/_pick_variant b/Completion/Base/Utility/_pick_variant
new file mode 100644
index 000000000..a80cddb26
--- /dev/null
+++ b/Completion/Base/Utility/_pick_variant
@@ -0,0 +1,35 @@
+#autoload
+
+local output cmd pat
+local -a var
+local -A opts
+
+(( $+_cmd_variant )) || typeset -gA _cmd_variant
+
+zparseopts -D -A opts c: r:
+: ${opts[-c]:=$words[1]}
+
+while [[ $1 = *=* ]]; do
+  var+=( "${1%%\=*}" "${1#*=}" )
+  shift
+done
+if (( $+_cmd_variant[$opts[-c]] )); then
+  (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}"
+  [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1
+  return 0
+fi
+
+output="$(_call_program variant $opts[-c] "${@[2,-1]}" </dev/null 2>&1)"
+
+for cmd pat in "$var[@]"; do
+  if [[ $output = *$~pat* ]]; then
+    (( $+opts[-r] )) && eval "${opts[-r]}=$cmd"
+    _cmd_variant[$opts[-c]]="$cmd"
+    return
+  fi
+done
+
+(( $+opts[-r] )) && eval "${opts[-r]}=$1"
+_cmd_variant[$opts[-c]]="$1"
+
+return 1
diff --git a/Completion/Unix/Command/_cpio b/Completion/Unix/Command/_cpio
index 61c4d76ac..280a8930f 100644
--- a/Completion/Unix/Command/_cpio
+++ b/Completion/Unix/Command/_cpio
@@ -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 @@ else
 	  '-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 @@ else
 	  '*: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'
diff --git a/Completion/Unix/Command/_grep b/Completion/Unix/Command/_grep
index 5dbbe025e..98b4256f8 100644
--- a/Completion/Unix/Command/_grep
+++ b/Completion/Unix/Command/_grep
@@ -16,17 +16,6 @@ else
   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 @@ arguments=( $arguments[@]
 )
 
 # remove long options?
-[[ -z "$_is_gnu[$command]" ]] &&
+_pick_variant -c "$command" gnu=gnu unix --help ||
     arguments=( ${arguments:#(|*\)(\*|))--*} )
 
 _arguments -s $arguments[@]
diff --git a/Completion/Unix/Command/_iconv b/Completion/Unix/Command/_iconv
index 3764c4634..490d70bc8 100644
--- a/Completion/Unix/Command/_iconv
+++ b/Completion/Unix/Command/_iconv
@@ -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' \
diff --git a/Completion/Unix/Command/_ls b/Completion/Unix/Command/_ls
index b9588c5f4..33c3ca652 100644
--- a/Completion/Unix/Command/_ls
+++ b/Completion/Unix/Command/_ls
@@ -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 @@ arguments=(
 )
 
 # remove long options?
-[[ -z "$_is_gnu[$words[1]]" ]] &&
+_pick_variant gnu=gnu unix --help ||
     arguments=( ${${${arguments:#(|*\))--*}//--[^ )]#/}/\( #\)/} )
 
 _arguments -s $arguments
diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
index df28eac60..53958c0d0 100644
--- a/Completion/Unix/Command/_make
+++ b/Completion/Unix/Command/_make
@@ -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 @@ else
     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
diff --git a/Completion/Unix/Command/_netcat b/Completion/Unix/Command/_netcat
index d5e854e12..082b8afde 100644
--- a/Completion/Unix/Command/_netcat
+++ b/Completion/Unix/Command/_netcat
@@ -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
diff --git a/Completion/Unix/Command/_zcat b/Completion/Unix/Command/_zcat
index dac7493b2..6dd4ecd7b 100644
--- a/Completion/Unix/Command/_zcat
+++ b/Completion/Unix/Command/_zcat
@@ -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 "$@"
diff --git a/Completion/Unix/Type/_diff_options b/Completion/Unix/Type/_diff_options
index cc25a8ae8..7b16fb458 100644
--- a/Completion/Unix/Type/_diff_options
+++ b/Completion/Unix/Type/_diff_options
@@ -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 \
diff --git a/Completion/X/Command/_nedit b/Completion/X/Command/_nedit
index f25ad503a..c915c25ec 100644
--- a/Completion/X/Command/_nedit
+++ b/Completion/X/Command/_nedit
@@ -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 @@ nedit_common=( \
   '*-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]' \
diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle
index bec258e1f..5abfe824e 100644
--- a/Completion/Zsh/Command/_zstyle
+++ b/Completion/Zsh/Command/_zstyle
@@ -141,7 +141,7 @@ taglist=(
   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 \