summary refs log tree commit diff
path: root/Completion/Zsh/Command/_zpty
blob: ef4ac4bb15e577bb8b645ca9e92fe66a8a80cb75 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#compdef zpty

local state line list names expl curcontext="$curcontext"
typeset -A opt_args

_arguments -C -s -S \
  '(-r -w -t -n -L -d)-e[echo input characters]' \
  '(-r -w -t -n -L -d)-b[io to pseudo-terminal blocking]' \
  '(-r -w -t -n -L -e -b)-d[delete command]:*:name:->name' \
  '(-r -L -t -e -b -d)-w[send string to command]:name:->name:*:strings to write' \
  '(-r -L -t -e -b -d)-n[do not add a newline to the result]' \
  '(: -r -w -t -n -e -b -d)-L[list defined commands as calls]' \
  '(: -w -n -L -e -b -d)-r[read string from command]:name:->name:param: _vars:pattern:' \
  '(: -w -n -L -e -b -d)-t[test if output is available before reading]' \
  '(-r -w -t -n -L -d):zpty command name:' \
  '(-r -w -t -n -L -d):cmd: _command_names -e' \
  '(-r -w -t -n -L -d)*::args:_precommand' && return 0

# One could use sets, but that's more expensive and zpty is simple enough.
#
# _arguments -C -s -S \
#   - read \
#     '-r[read string from command]' \
#     '-t[test if output is available first]' \
#     ':name:->name' \
#     ':param: _vars' \
#     ':pattern:' \
#   - write \
#     '-w[send string to command]' \
#     '-n[do not add a newline to the result]' \
#     ':name:->name' \
#     '*:strings to write' \
#   - list \
#     '-L[list defined commands as calls]' \
#   - delete \
#     '-d[delete command]' \
#     '*:name:->name' \
#   - start \
#     '-e[echo input characters]' \
#     '-b[io to pseudo-terminal blocking]' \
#     ':zpty command name:' \
#     ':cmd: _command_names -e' \
#     '*::args:_precommand' && return 0


if [[ $state = name ]]; then
  if ! zmodload -e zsh/zpty; then
    _message "zpty module not loaded"
    return 1
  fi
  list=( ${${(f)"$(zpty)"}#*\) } )
  names=( ${list%%:*} )
  if zstyle -T ":completion:${curcontext}" verbose; then
    zformat -a list ' --' ${${(f)"$(zpty)"}#*\) }
    _wanted names expl 'zpty command name' compadd -d list -a names
  else
    _wanted names expl 'zpty command name' compadd -a names
  fi
else
  return 1
fi