diff options
Diffstat (limited to 'Completion/Base')
-rw-r--r-- | Completion/Base/_combination | 63 | ||||
-rw-r--r-- | Completion/Base/_command_names | 32 | ||||
-rw-r--r-- | Completion/Base/_describe | 4 | ||||
-rw-r--r-- | Completion/Base/_equal | 10 | ||||
-rw-r--r-- | Completion/Base/_subscript | 6 | ||||
-rw-r--r-- | Completion/Base/_tilde | 6 | ||||
-rw-r--r-- | Completion/Base/_value | 2 |
7 files changed, 78 insertions, 45 deletions
diff --git a/Completion/Base/_combination b/Completion/Base/_combination index 631547311..dcb3269cd 100644 --- a/Completion/Base/_combination +++ b/Completion/Base/_combination @@ -1,25 +1,27 @@ #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 `users-hosts-ports' as for the my-accounts +# tag: # -# telnet_hosts_ports_users=( -# host0:: host1::user1 host2::user2 -# mail-server:{smtp,pop3}: -# news-server:nntp: -# proxy-server:8000: -# ) +# zstyle ':completion:*:*:telnet:*:my-accounts' users-hosts-ports \ +# @host0: user1@host1: user2@host2: +# @mail-server:{smtp,pop3} +# @news-server:nntp +# @proxy-server:8000 +# # -# `_telnet completes' hosts as: +# `_telnet' completes hosts as: # -# _combination telnet_hosts_ports_users \ -# ${options[-l]:+users=${options[-l]:q}} \ +# _combination my-accounts users-hosts-ports \ +# ${opt_args[-l]:+users=${opt_args[-l]:q}} \ # hosts "$expl[@]" # # This completes `host1', `host2', `mail-server', `news-server' and @@ -28,8 +30,8 @@ # # `_telnet' completes ports as: # -# _combination telnet_hosts_ports_users \ -# ${options[-l]:+users=${options[-l]:q}} \ +# _combination my-accounts users-hosts-ports \ +# ${opt_args[-l]:+users=${opt_args[-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 users-hosts-ports \ # ${line[2]:+hosts="${line[2]:q}"} \ # ${line[3]:+ports="${line[3]:q}"} \ # users "$expl[@]" @@ -48,25 +50,23 @@ # 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" shift 2 +elif [[ "$1" = -s* ]]; then + sep="${1[3,-1]}" + shift 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,15 +81,14 @@ key="${1%:*}" num="${${1##*:}:-1}" shift -if (( ${(P)+${var}} )); then - eval "tmp=( \"\${(@M)${var}:#\${(j($sep))~pats}}\" )" +if zstyle -a ":completion:${curcontext}:$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} )" + eval "tmp=( \${tmp#\${(j(${sep}))~\${(@)\${(@)keys[2,(rn:num:)\$key]}/*/*}}${~sep}} )" fi - tmp=( ${tmp%%$sep*} ) + tmp=( ${tmp%%${~sep}*} ) - compadd "$@" - $tmp || { builtin functions _$key >&- && _$key "$@" } + compadd "$@" -a tmp || { (( $+functions[_$key] )) && "_$key" "$@" } else - builtin functions _$key >&- && _$key "$@" + (( $+functions[_$key] )) && "_$key" "$@" fi - diff --git a/Completion/Base/_command_names b/Completion/Base/_command_names index d3b8a109a..844f190a6 100644 --- a/Completion/Base/_command_names +++ b/Completion/Base/_command_names @@ -1,3 +1,31 @@ -#defcomp -command- +#compdef -command- -complist -c +# The option `-e' if given as the first argument says that we should +# complete only external commands and executable files. This and a +# `-' as the first argument is then removed from the arguments. + +local args defs + +defs=( + 'commands:external command:compadd -k commands' + 'executables:executable file or directory:_path_files -/g \*\(-\*\)' +) + +if [[ "$1" = -e ]]; then + shift +else + [[ "$1" = - ]] && shift + + defs=( "$defs[@]" + 'builtins:builtin command:compadd -k builtins' + 'functions:shell function:compadd -k functions' + 'aliases:alias:compadd -k aliases' + 'reserved-words:reserved word:compadd -k reswords' + 'jobs:: _jobs -t' + 'parameters:: _parameters -qS= -r "\n\t\- =["' + ) +fi + +args=( "$@" ) + +_alternative -O args "$defs[@]" diff --git a/Completion/Base/_describe b/Completion/Base/_describe index 5aeeadf10..a658d16df 100644 --- a/Completion/Base/_describe +++ b/Completion/Base/_describe @@ -52,8 +52,8 @@ while _tags; do fi fi - compadd "$_args[@]" "$_expl[@]" -ld _tmpd - "$_tmpmd[@]" && _ret=0 - compadd "$_args[@]" "$_expl[@]" -d _tmps - "$_tmpms[@]" && _ret=0 + compadd "$_args[@]" "$_expl[@]" -ld _tmpd -a _tmpmd && _ret=0 + compadd "$_args[@]" "$_expl[@]" -d _tmps -a _tmpms && _ret=0 done done (( _ret )) || return 0 diff --git a/Completion/Base/_equal b/Completion/Base/_equal index f407014fe..4150fe629 100644 --- a/Completion/Base/_equal +++ b/Completion/Base/_equal @@ -1,3 +1,9 @@ -#defcomp -equal- +#compdef -equal- -compgen -am +local args + +args=( "$@" ) + +_alternative -O args \ + 'commands:command:compadd -k commands' \ + 'aliases:alias:compadd -k aliases' diff --git a/Completion/Base/_subscript b/Completion/Base/_subscript index 60d45370b..e3bde552a 100644 --- a/Completion/Base/_subscript +++ b/Completion/Base/_subscript @@ -12,7 +12,7 @@ elif [[ ${(Pt)${compstate[parameter]}} = assoc* ]]; then [[ "$RBUFFER" != \]* ]] && suf=']' _wanted association-keys expl 'association key' \ - compadd -S "$suf" - "${(@kP)${compstate[parameter]}}" + compadd -S "$suf" -k "$compstate[parameter]" elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then local list i j ret=1 disp @@ -39,10 +39,10 @@ elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then if [[ "$RBUFFER" = \]* ]]; then _all_labels -V indexes expl 'array index' \ - compadd -S '' "$disp[@]" - "$ind[@]" && ret=0 + compadd -S '' "$disp[@]" -a ind && ret=0 else _all_labels -V indexes expl 'array index' \ - compadd -S ']' "$disp[@]" - "$ind[@]" && ret=0 + compadd -S ']' "$disp[@]" -a ind && ret=0 fi fi _requested parameters && _parameters && ret=0 diff --git a/Completion/Base/_tilde b/Completion/Base/_tilde index 59ac8d0f6..43c9b3ea4 100644 --- a/Completion/Base/_tilde +++ b/Completion/Base/_tilde @@ -2,7 +2,7 @@ # We use all named directories and user names here. If this is too slow # for you or if there are too many of them, you may want to use -# `compadd -qS/ - "$friends[@]"' or something like that. +# `compadd -qS/ -a friends' or something like that. [[ -n "$compstate[quote]" ]] && return 1 @@ -22,7 +22,7 @@ while _tags; do _requested users && _users "$suf[@]" "$@" && ret=0 _requested named-directories expl 'named directory' \ - compadd "$suf[@]" "$@" - "${(@k)nameddirs}" + compadd "$suf[@]" "$@" -k nameddirs if _requested directory-stack && { ! zstyle -T ":completion:${curcontext}:directory-stack" prefix-needed || @@ -50,7 +50,7 @@ while _tags; do disp=() fi _all_labels -V directory-stack expl 'directory stack' \ - compadd "$suf[@]" "$disp[@]" -Q - "$list[@]" && ret=0 + compadd "$suf[@]" "$disp[@]" -Q -a list && ret=0 fi (( ret )) || return 0 done diff --git a/Completion/Base/_value b/Completion/Base/_value index 9df71fdd4..402bab236 100644 --- a/Completion/Base/_value +++ b/Completion/Base/_value @@ -10,7 +10,7 @@ _value () { "${(Pt)${compstate[parameter]}}" = assoc* ]]; then if (( CURRENT & 1 )); then _wanted association-keys expl 'association key' \ - compadd - "${(@kP)${compstate[parameter]}}" + compadd -k "$compstate[parameter]" else compstate[parameter]="${compstate[parameter]}-${words[CURRENT-1]}" _value "$@" |