about summary refs log tree commit diff
path: root/Completion/User/_user_at_host
blob: 1098d2342c87da5d3c0b2ef699b384ad62c8264e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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%%@*}

  compset -P 1 '*@'

  _wanted -C user-at hosts expl "host for $user" &&
      _combination "${tag}" users-hosts users="$user" hosts "$expl[@]" "$@"
else
  _wanted users expl "user" &&
      _combination "${tag}" users-hosts users -S@ -q "$expl[@]" "$@"
fi