about summary refs log tree commit diff
path: root/Completion/User/_combination
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/User/_combination')
-rw-r--r--Completion/User/_combination28
1 files changed, 19 insertions, 9 deletions
diff --git a/Completion/User/_combination b/Completion/User/_combination
index a122bd86f..631547311 100644
--- a/Completion/User/_combination
+++ b/Completion/User/_combination
@@ -1,9 +1,9 @@
 #autoload
 
 # Usage:
-#   _combination [-s SEP] VARIABLE KEYi=PATi KEYj=PATj ... KEYm=PATm KEY EXPL...
+#   _combination [-s S] V[:K1:...] Ki1[:Ni1]=Pi1 Ki2[:Ni2]=Pi2 ... Kim[:Nim]=Pim Kj[:Nj] EXPL...
 #
-#  VARIABLE must be formd as PREFIX_KEY1_..._KEYn.
+#  It is assumed that V is formed as PRE_K1_..._Kn if `:K1:...' is not specified.
 #
 # Example: telnet
 #
@@ -48,7 +48,7 @@
 #  the port argument if they are exist. And if it is failed, `_users' is
 #  called.
 
-local sep var keys pats key tmp
+local sep var keys pats key num tmp
 
 if [[ "$1" = -s ]]; then
   sep="$2"
@@ -60,21 +60,31 @@ fi
 var=$1
 shift
 
-keys=( "${(@s:_:)${var#*_}}" )
+if [[ $var = *:* ]]; then
+  keys=( ${(s/:/)var} )
+  shift keys
+  var="${var%%:*}"
+else
+  keys=( "${(@s:_:)${var#*_}}" )
+fi
 pats=( "${(@)keys/*/*}" )
 
 while [[ "$1" = *=* ]]; do
-  pats[$keys[(i)${1%%\=*}]]="${1#*\=}"
+  tmp="${1%%\=*}"
+  key="${tmp%:*}"
+  num="${${tmp##*:}:-1}"
+  pats[$keys[(in:num:)$key]]="${1#*\=}"
   shift
 done
 
-key="$1"
+key="${1%:*}"
+num="${${1##*:}:-1}"
 shift
 
 if (( ${(P)+${var}} )); then
-  eval "tmp=( \"\${(@M)${var}:#\${(j!$sep!)~pats}}\" )"
-  if (( keys[(i)$key] != 1 )); then
-    eval "tmp=( \${tmp#\${(j!${sep}!)~\${(@)\${(@)keys[2,(r)\$key]}/*/*}}$sep} )"
+  eval "tmp=( \"\${(@M)${var}:#\${(j($sep))~pats}}\" )"
+  if (( keys[(in:num:)$key] != 1 )); then
+    eval "tmp=( \${tmp#\${(j(${sep}))~\${(@)\${(@)keys[2,(rn:num:)\$key]}/*/*}}$sep} )"
   fi
   tmp=( ${tmp%%$sep*} )