about summary refs log tree commit diff
path: root/Completion/Base/Utility
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/Base/Utility
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/Base/Utility')
-rw-r--r--Completion/Base/Utility/.distfiles2
-rw-r--r--Completion/Base/Utility/_pick_variant35
2 files changed, 36 insertions, 1 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