diff options
Diffstat (limited to 'Completion/Base/_combination')
-rw-r--r-- | Completion/Base/_combination | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/Completion/Base/_combination b/Completion/Base/_combination index 69ae973f9..97da22a5f 100644 --- a/Completion/Base/_combination +++ b/Completion/Base/_combination @@ -1,24 +1,26 @@ #autoload # Usage: -# _combination [-s S] V[:K1:...] Ki1[:Ni1]=Pi1 Ki2[:Ni2]=Pi2 ... Kim[:Nim]=Pim Kj[:Nj] EXPL... +# _combination [-s S] TAG STYLE \ +# Ki1[:Ni1]=Pi1 Ki2[:Ni2]=Pi2 ... Kim[:Nim]=Pim Kj[:Nj] EXPL... # -# It is assumed that V is formed as PRE_K1_..._Kn if `:K1:...' is not specified. +# STYLE should be of the form K1-K2-...-Kn. # # Example: telnet # -# Assume an user sets the variable `telnet_hosts_ports_users' as: +# Assume an user sets the style `hosts-ports-users' as for the my-accounts +# tag: # -# telnet_hosts_ports_users=( +# compstyle '*:telnet*:my-accounts' hosts-ports-users \ # host0:: host1::user1 host2::user2 # mail-server:{smtp,pop3}: # news-server:nntp: # proxy-server:8000: -# ) +# # -# `_telnet completes' hosts as: +# `_telnet' completes hosts as: # -# _combination telnet_hosts_ports_users \ +# _combination my-accounts hosts-ports-users \ # ${options[-l]:+users=${options[-l]:q}} \ # hosts "$expl[@]" # @@ -28,7 +30,7 @@ # # `_telnet' completes ports as: # -# _combination telnet_hosts_ports_users \ +# _combination my-accounts hosts-ports-users \ # ${options[-l]:+users=${options[-l]:q}} \ # hosts="${line[2]:q}" \ # ports "$expl[@]" @@ -39,7 +41,7 @@ # # `_telnet' completes users for an argument of option `-l' as: # -# _combination telnet_hosts_ports_users \ +# _combination my-accounts hosts-ports-users \ # ${line[2]:+hosts="${line[2]:q}"} \ # ${line[3]:+ports="${line[3]:q}"} \ # users "$expl[@]" @@ -48,7 +50,7 @@ # the port argument if they are exist. And if it is failed, `_users' is # called. -local sep var keys pats key num tmp +local sep tag style keys pats key num tmp if [[ "$1" = -s ]]; then sep="$2" @@ -57,16 +59,11 @@ else sep=: fi -var=$1 -shift +tag="$1" +style="$2" +shift 2 -if [[ $var = *:* ]]; then - keys=( ${(s/:/)var} ) - shift keys - var="${var%%:*}" -else - keys=( "${(@s:_:)${var#*_}}" ) -fi +keys=( ${(s/-/)style} ) pats=( "${(@)keys/*/*}" ) while [[ "$1" = *=* ]]; do @@ -81,8 +78,8 @@ key="${1%:*}" num="${${1##*:}:-1}" shift -if (( ${(P)+${var}} )); then - eval "tmp=( \"\${(@M)${var}:#\${(j($sep))~pats}}\" )" +if _style -a "$tag" "$style" tmp; then + eval "tmp=( \"\${(@M)tmp:#\${(j($sep))~pats}}\" )" if (( keys[(in:num:)$key] != 1 )); then eval "tmp=( \${tmp#\${(j(${sep}))~\${(@)\${(@)keys[2,(rn:num:)\$key]}/*/*}}$sep} )" fi @@ -92,4 +89,3 @@ if (( ${(P)+${var}} )); then else (( $+functions[_$key] )) && "_$key" "$@" fi - |