about summary refs log tree commit diff
path: root/Completion/User/_nslookup
blob: 7d2a12142a348fe0d89d44e6400e4c280b542d46 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#compdef nslookup

# This may also be called from the `nslookup' wrapper function during
# `vared'iting a line.
# In this case this function tries to call other user-defined functions
# for certain contexts before adding completion. If these functions are
# defined, they are called and the default completions from this function
# are not added. The functions called are named `_nslookup_<state>', with
# `<state>' being any of:
#
#  command
#    When completing the first word on the line.
#  redirect
#    When completing after a redirection operator.
#
# Also, when completing after the first word, if the first word contains
# only lower case letters, we try to call the function `_nslookup_<word>',
# where `<word>' is the first word from the line. If the first word contains
# other characters than lower case letters, we try to call the function
# `_nslookup_host'.

setopt localoptions extendedglob

local state expl ret=1 setopts

setopts=(
  'all[print current values]' \
  '(nodebug)debug[simple debugging information]' \
  '(debug)nodebug[no simple debugging information]' \
  '(nod2)d2[extra debugging information]' \
  '(d2)nod2[no extra debugging information]' \
  '(nodefname)defname[append default domain name]' \
  '(defname)nodefname[don'"'"'t append default domain name]' \
  '(nosearch)search[append search list]' \
  '(search)nosearch[don'"'"'t append search list]' \
  '(norecurse)recurse[name server may query other servers]' \
  '(recurse)norecurse[name server may not query other servers]' \
  '(novc)vc[use virtual circuit]' \
  '(vc)novc[don'"'"'t use virtual circuit]' \
  '(noignoretc)ignoretc[ignore packet truncation errors]' \
  '(ignoretc)noignoretc[don'"'"'t ignore packet truncation errors]' \
  'class[change query class]:query class:((in\:Internet\ class chaos\:CHAOS\ class hesiod\:MIT\ Athena\ Hesiod\ class any\:wildcard\ \(any\ of\ the\ above\)))'
  'domain[change default domain]:default domain:_hosts'
  'srchlist[change default domain and search list]: :->srchlist'
  'port[change name server port]:name server port:'
  {query,}type'[change type of information query]:query information type:((a\:internet\ address cname\:canonical\ name\ for\ alias hinfo\:CPU\ and\ operating\ system\ type minfo\:mailbox\ or\ mail\ list\ information mx\:mail\ exchanger ns\:name\ server\ for\ zone ptr\:host\ name\ or\ other\ information soa\:domain\'"'"'s\ \`start-of-authority\'"'"'\ information txt\:text\ information uinfo\:user\ information wks\:supported\ well-known\ services))'
  'retry[change number of retries]:number of retries:'
  'root[change name of root server]:root server:_hosts'
  'timeout[change initial timeout interval]:timeout (seconds):'
)

if [[ -n "$compcontext" ]]; then
  if [[ CURRENT -eq 1 ]]; then

    funcall ret _nslookup_command && return ret

    _description expl 'command'
    compadd "$expl[@]" - server lserver root finger ls view help set && ret=0
    _hosts && ret=0
    return ret
  elif [[ "$compstate[context]" = redirect ]]; then

    funcall ret _nslookup_redirect && return ret

    if [[ "$words[1]" != (finger|ls) ]]; then
      _message "redirection not allowed for command \`$words[1]'"
      return 1
    elif [[ "$compstate[redirect]" = '>' ]]; then
      _description expl 'write to file'
    elif [[ "$compstate[redirect]" = '>>' ]]; then
      _description expl 'append to file'
    else
      _message "unknown redirection operator \`$compstate[redirect]'"
      return 1
    fi

    _files "$expl[@]"
    return
  fi

  if [[ "$words[1]" = [a-z]## ]]; then
    funcall ret _nslookup_$words[1] && return ret
  else
    funcall ret _nslookup_host && return ret
  fi

  case "$words[1]" in
  (|l)server)
    _description expl 'new default server'
    _hosts "$expl[@]"
    return
    ;;
  root|exit|help|\?)
    return 1
    ;;
  finger)
    _message 'finger name'
    return 1
    ;;
  ls)
    _arguments -s \
      '-t[records of given type]:query information type:((a\:internet\ address cname\:canonical\ name\ for\ alias hinfo\:CPU\ and\ operating\ system\ type minfo\:mailbox\ or\ mail\ list\ information mx\:mail\ exchanger ns\:name\ server\ for\ zone ptr\:host\ name\ or\ other\ information soa\:domain\'"'"'s\ \`start-of-authority\'"'"'\ information txt\:text\ information uinfo\:user\ information wks\:supported\ well-known\ services))' \
     '-a[aliases of hosts in domain]' \
     '-d[all records]' \
     '-h[CPU and operating system information]' \
     '-s[well-known services]' \
     ':domain:_hosts'
    return
    ;;
  view)
    _description expl 'view file'
    _files "$expl[@]"
    return
    ;;
  set)
    typeset -A values

    _values 'state information' "$setopts[@]" && ret=0

    [[ -z "$state" ]] && return ret
    ;;
  *)
    _description expl 'server'
    _hosts "$expl[@]"
    return
  esac
fi

# Now comes the command line option completion part.

if [[ -z "$state" ]]; then
  local line
  typeset -A options

  _arguments \
    "-${(@)^${(@M)setopts:#*\]:*}/\[/=[}" \
    "-${(@)^setopts:#(\(|*\]:)*}" \
    "${(@)^${(@)${(@M)setopts:#\(*}/\)/)-}/\(/(-}" \
    ':host to find:_hosts' \
    ':server:_hosts' && ret=0
fi

# This is completion after `srchlist' for both types.

if [[ -n "$state" ]]; then
  if compset -P '*/'; then
    _description expl 'search list entry'
  else
    _description expl 'default domain name and first search list entry'
  fi
  if [[ -n "$_vals_cache_multi" ]]; then
    _hosts "$expl[@]" -qS/ -r "/\\- \\t\\n$_vals_cache_multi"
  else
    _hosts "$expl[@]" -qS/
  fi
  return
fi

return ret