diff options
author | Tanaka Akira <akr@users.sourceforge.net> | 1999-11-22 12:29:47 +0000 |
---|---|---|
committer | Tanaka Akira <akr@users.sourceforge.net> | 1999-11-22 12:29:47 +0000 |
commit | 3d9d13e918c195f974ff7b2f1dc5b65f6b20a441 (patch) | |
tree | d571aef9c8152287ed94dae1199108de80f0b984 /Completion/User | |
parent | a76b36928c5cbeef3fe015ca30bbf910ab2a107e (diff) | |
download | zsh-3d9d13e918c195f974ff7b2f1dc5b65f6b20a441.tar.gz zsh-3d9d13e918c195f974ff7b2f1dc5b65f6b20a441.tar.xz zsh-3d9d13e918c195f974ff7b2f1dc5b65f6b20a441.zip |
zsh-workers/8720
Diffstat (limited to 'Completion/User')
-rw-r--r-- | Completion/User/_groups | 19 | ||||
-rw-r--r-- | Completion/User/_hosts | 9 | ||||
-rw-r--r-- | Completion/User/_my_accounts | 12 | ||||
-rw-r--r-- | Completion/User/_other_accounts | 12 | ||||
-rw-r--r-- | Completion/User/_ports | 9 | ||||
-rw-r--r-- | Completion/User/_rlogin | 18 | ||||
-rw-r--r-- | Completion/User/_socket | 10 | ||||
-rw-r--r-- | Completion/User/_ssh | 16 | ||||
-rw-r--r-- | Completion/User/_telnet | 6 | ||||
-rw-r--r-- | Completion/User/_user_at_host | 23 | ||||
-rw-r--r-- | Completion/User/_users | 4 |
11 files changed, 64 insertions, 74 deletions
diff --git a/Completion/User/_groups b/Completion/User/_groups index f1963a8e7..0007c1791 100644 --- a/Completion/User/_groups +++ b/Completion/User/_groups @@ -1,15 +1,18 @@ #compdef newgrp -local expl +local expl groups _wanted groups expl group || return 1 -if (( ! $+groups )); then - if (( ${+commands[ypcat]} )); then - : ${(A)groups:=${${(s: :)$(ypcat group.byname)}%%:*}} # If you use YP - else - : ${(A)groups:=${${(s: :)$(</etc/group)}%%:*}} - fi +if ! _style -a groups groups groups; then + (( $+_cache_groups )) || + if (( ${+commands[ypcat]} )); then + : ${(A)_cache_groups:=${${(s: :)$(ypcat group.byname)}%%:*}} # If you use YP + else + : ${(A)_cache_groups:=${${(s: :)$(</etc/group)}%%:*}} + fi + + groups=( "$_cache_groups[@]" ) fi -compadd "$@" "$expl[@]" - $groups +compadd "$@" "$expl[@]" - "$groups[@]" diff --git a/Completion/User/_hosts b/Completion/User/_hosts index 83480efe4..196f40c83 100644 --- a/Completion/User/_hosts +++ b/Completion/User/_hosts @@ -1,8 +1,13 @@ #compdef ftp ncftp ping rwho rup xping traceroute host -local expl +local expl hosts -: ${(A)hosts:=${(s: :)${(ps:\t:)${${(f)"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} +if ! _style -a hosts hosts hosts; then + (( $+_cache_hosts )) || + : ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${${(f)"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} + + hosts=( "$_cache_hosts[@]" ) +fi _wanted hosts expl host && compadd -M 'm:{a-zA-Z}={A-Za-z} r:|.=* r:|=*' "$@" "$expl[@]" - "$hosts[@]" diff --git a/Completion/User/_my_accounts b/Completion/User/_my_accounts index 34d6269d4..267cdd6f1 100644 --- a/Completion/User/_my_accounts +++ b/Completion/User/_my_accounts @@ -1,13 +1,3 @@ #autoload -local accounts_users_hosts - -local varname="$words[1]_accounts" - -if [[ ${(P)+varname} -eq 1 ]]; then - accounts_users_hosts=( ${(P)varname} ) -else - accounts_users_hosts=( $my_accounts ) -fi - -_user_at_host "$@" +_user_at_host -t my-accounts "$@" diff --git a/Completion/User/_other_accounts b/Completion/User/_other_accounts index 9e3545e98..b419791e5 100644 --- a/Completion/User/_other_accounts +++ b/Completion/User/_other_accounts @@ -1,13 +1,3 @@ #compdef talk ntalk ytalk finger -local accounts_users_hosts - -local varname="$words[1]_accounts" - -if [[ ${(P)+varname} -eq 1 ]]; then - accounts_users_hosts=( ${(P)varname} ) -else - accounts_users_hosts=( $other_accounts ) -fi - -_user_at_host "$@" +_user_at_host -t other-accounts "$@" diff --git a/Completion/User/_ports b/Completion/User/_ports index ffd04ce5e..da59fd4ea 100644 --- a/Completion/User/_ports +++ b/Completion/User/_ports @@ -1,7 +1,12 @@ #autoload -local expl +local expl ports -: ${(A)ports:=${${(M)${${(f)"$(</etc/services)"}:#\#*}#*/tcp}%%[ ]*}} +if ! _style ports ports ports; then + (( $+_cache_ports )) || + : ${(A)ports:=${${(M)${${(f)"$(</etc/services)"}:#\#*}#*/tcp}%%[ ]*}} + + ports=( "$_cache_ports[@]" ) +fi _wanted ports expl port && compadd "$@" "$expl[@]" - "$ports[@]" diff --git a/Completion/User/_rlogin b/Completion/User/_rlogin index d732cf8a9..738b6225f 100644 --- a/Completion/User/_rlogin +++ b/Completion/User/_rlogin @@ -1,16 +1,6 @@ #compdef rlogin rsh remsh rcp _rlogin () { - local accounts_users_hosts - - local varname="$words[1]_accounts" - - if (( ${(P)+varname} )); then - accounts_users_hosts=( ${(P)varname} ) - else - accounts_users_hosts=( $my_accounts ) - fi - case "$words[1]" in rlogin) _arguments -s \ @@ -64,21 +54,21 @@ _rlogin () { } _rlogin_users () { - _tags users && _combination accounts_users_hosts users "$@" + _tags users && _combination my-accounts users-hosts users "$@" } _rlogin_hosts () { _tags hosts && if [[ "$IPREFIX" == *@ ]]; then - _combination accounts_users_hosts "users=${IPREFIX/@}" hosts "$@" + _combination my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" else - _combination accounts_users_hosts \ + _combination my-accounts users-hosts \ ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@" fi } _rlogin_all_hosts () { - _tags hosts && _combination accounts_users_hosts hosts "$@" + _tags hosts && _combination my-accounts users-hosts hosts "$@" } _rlogin "$@" diff --git a/Completion/User/_socket b/Completion/User/_socket index b155e7ad4..45374a403 100644 --- a/Completion/User/_socket +++ b/Completion/User/_socket @@ -1,9 +1,9 @@ #compdef socket -# Parameter used: +# Style used: # -# socket_hosts_ports -# The array that contains paris `host:port'. +# hosts-ports +# The style that contains pairs `host:port'. local curcontext="$curcontext" state line expl typeset -A opt_args @@ -41,14 +41,14 @@ arg1) _wanted ports expl 'port to listen' && _ports "$expl[@]" else _wanted hosts expl 'host' && - _combination socket_hosts_ports hosts "$expl[@]" + _combination '' hosts-ports hosts "$expl[@]" fi ;; arg2) if (( ! $+opt_args[-s] )); then _wanted ports expl 'port to connect' && - _combination socket_hosts_ports hosts="${line[2]:q}" ports "$expl[@]" + _combination '' hosts-ports hosts="${line[2]:q}" ports "$expl[@]" fi ;; esac diff --git a/Completion/User/_ssh b/Completion/User/_ssh index e7c6d37f6..4318caf96 100644 --- a/Completion/User/_ssh +++ b/Completion/User/_ssh @@ -4,16 +4,6 @@ _ssh () { local curcontext="$curcontext" state lstate line ret=1 expl args tmp typeset -A opt_args - local accounts_users_hosts - - local varname="$words[1]_accounts" - - if (( ${(P)+varname} )); then - accounts_users_hosts=( ${(P)varname} ) - else - accounts_users_hosts=( $my_accounts ) - fi - args=() # ssh-opt is a pseudo-command used to complete ssh options for `scp -o'. @@ -227,14 +217,14 @@ _ssh () { } _ssh_users () { - _combination accounts_users_hosts users "$@" + _combination my-accounts users-hosts users "$@" } _ssh_hosts () { if [[ "$IPREFIX" == *@ ]]; then - _combination accounts_users_hosts "users=${IPREFIX/@}" hosts "$@" + _combination my-accounts users-hosts "users=${IPREFIX/@}" hosts "$@" else - _combination accounts_users_hosts \ + _combination my-accounts users-hosts \ ${opt_args[-l]:+"users=${opt_args[-l]:q}"} hosts "$@" fi } diff --git a/Completion/User/_telnet b/Completion/User/_telnet index 597c0a021..7b86e544c 100644 --- a/Completion/User/_telnet +++ b/Completion/User/_telnet @@ -64,14 +64,14 @@ _arguments -C -s \ case "$state" in hosts) _wanted hosts expl host && - _combination telnet_hosts_ports_users \ + _combination '' hosts-ports-users \ ${opt_args[-l]:+users=${opt_args[-l]:q}} \ hosts "$expl[@]" ;; ports) _wanted ports expl port && - _combination telnet_hosts_ports_users \ + _combination '' hosts-ports-users \ ${opt_args[-l]:+users=${opt_args[-l]:q}} \ hosts="${line[2]:q}" \ ports "$expl[@]" @@ -79,7 +79,7 @@ ports) users) _wanted users expl user && - _combination telnet_hosts_ports_users \ + _combination '' hosts-ports-users \ ${line[2]:+hosts="${line[2]:q}"} \ ${line[3]:+ports="${line[3]:q}"} \ users "$expl[@]" diff --git a/Completion/User/_user_at_host b/Completion/User/_user_at_host index 78e5a12aa..1098d2342 100644 --- a/Completion/User/_user_at_host +++ b/Completion/User/_user_at_host @@ -1,13 +1,30 @@ #autoload +# Complete user/host combinations. Normally this looks for the style +# `users-hosts' for the tag `accounts'. A different tag may be given +# with `-t tag'. +# A `-' or `--' as the first argument is ignored. + +local tag=accounts + +if [[ "$1" = -t?* ]]; then + tag="${1[3,-1]}" + shift +elif [[ "$1" = -t ]]; then + tag="$2" + shift 2 +fi + +[[ "$1" = -(|-) ]] && shift + if [[ -prefix 1 *@ ]]; then - local user=${PREFIX/@} + local user=${PREFIX%%@*} compset -P 1 '*@' _wanted -C user-at hosts expl "host for $user" && - _combination accounts_users_hosts users="$user" hosts "$expl[@]" "$@" + _combination "${tag}" users-hosts users="$user" hosts "$expl[@]" "$@" else _wanted users expl "user" && - _combination accounts_users_hosts users -S@ -q "$expl[@]" "$@" + _combination "${tag}" users-hosts users -S@ -q "$expl[@]" "$@" fi diff --git a/Completion/User/_users b/Completion/User/_users index fdef36073..8ddfd8cd7 100644 --- a/Completion/User/_users +++ b/Completion/User/_users @@ -3,11 +3,11 @@ # If a parameter `users' exists and it is an array, we first try to # complete only to its elements. -local expl +local expl users _wanted users expl user || return 1 -[[ "${(t)users}" = *array* ]] && +_style -a users users users && compadd "$expl[@]" "$@" - "$users[@]" && return 0 compadd "$@" "$expl[@]" - "${(@k)userdirs}" |