about summary refs log tree commit diff
path: root/Completion/User/_socket
blob: c7605a1acfd07d4d7327b719c54662cf612e1f7e (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#compdef socket

# Parameter used:
#
#  socket_ports
#    The associative array that maps a host name to a space-separated list of 
#    ports.


local state line expl
typeset -A options

_arguments -s \
  -{b,c,f,q,r,v,w} \
  -{s,l} \
  '-p:command:->command' \
  ':arg1:->arg1' \
  ':arg2:->arg2'

case "$state" in
command)
  compset -q
  _normal
  ;;

arg1)
  if (( $+options[-s] )); then
    _message 'port to listen'
  else
    _description expl 'host'
    compadd "$expl[@]" - ${(k)socket_ports} || _hosts "$expl[@]"
  fi
  ;;

arg2)
  if (( ! $+options[-s] )); then
    _description expl 'port to connect'
    if (( $+socket_ports )); then
      compadd "$expl[@]" - ${=socket_ports[$line[2]]};
    else
      _message 'port to connect';
    fi
  fi
  ;;
esac