summaryrefslogtreecommitdiff
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
parent2fa33574f029358dc1597b1ff8700385d7c8332a (diff)
downloadzsh-79323d6d41c91860cd05800a06cf8076df5051bd.tar.gz
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
-rw-r--r--ChangeLog10
-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
-rw-r--r--Doc/Zsh/compsys.yo28
14 files changed, 94 insertions, 98 deletions
diff --git a/ChangeLog b/ChangeLog
index 81363167e..4d6e6ccb6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2002-03-15 Oliver Kiddle <opk@zsh.org>
+ * 16842: Completion/Base/Utility/_pick_variant,
+ Completion/Base/Utility/.distfiles, Completion/Unix/Command/_cpio,
+ Completion/Unix/Command/_grep, Completion/Unix/Command/_iconv,
+ Completion/Unix/Command/_ls, Completion/Unix/Command/_make,
+ Completion/Unix/Command/_netcat, Completion/Unix/Command/_zcat,
+ Completion/Unix/Type/_diff_options, Completion/X/Command/_nedit,
+ Completion/Zsh/Command/_zstyle, Doc/Zsh/compsys.yo:
+ resolve name clash for nc between netcat and the nedit client
+ and add utility function to handle the general case of this
+
* 16838: Completion/Unix/Command/_grep: complete new options of
grep 2.5 and value for GREP_OPTIONS parameter
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 \
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 48acd9bfe..f69c8a3d7 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -864,10 +864,10 @@ item(tt(values))(
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))(
@@ -3942,6 +3942,26 @@ These functions also accept the `tt(-J)', `tt(-V)', `tt(-1)',
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 function is a compiler to generate a completion function. The