Skip to content

Commit f6f147f

Browse files
committed
Improve iw completion
1 parent 84f26c4 commit f6f147f

File tree

1 file changed

+199
-93
lines changed
  • completions

1 file changed

+199
-93
lines changed

completions/iw

Lines changed: 199 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1+
# iw(8) completion -*- shell-script -*-
2+
13
_iw()
24
{
35
local cur prev words cword
46
_init_completion || return
57

6-
case $prev in
7-
--version)
8-
return
9-
;;
10-
esac
11-
12-
# find last word typed
138
local subcword obj cmd
14-
for (( subcword=1; subcword < ${#words[@]}-1; subcword++ )); do
15-
[[ ${words[subcword]} == '--version' ]] && return
16-
[[ -n $obj ]] && break
9+
for (( subcword=1; subcword < cword; subcword++ )); do
10+
[[ ${words[subcword]} = --version ]] && return
11+
if [[ -n $obj ]]; then
12+
case $obj in
13+
phy|dev|wdev)
14+
if [[ $subcword+1 -lt $cword ]]; then
15+
cmd=${words[subcword+1]}
16+
(( subcword++ ))
17+
break
18+
fi
19+
;;
20+
esac && break
21+
fi
1722
[[ ${words[subcword]} != -* ]] && obj=${words[subcword]}
1823
done
1924

20-
2125
if [[ -z $obj ]]; then
2226
case $cur in
2327
-*)
@@ -26,102 +30,204 @@ _iw()
2630
return
2731
;;
2832
*)
29-
COMPREPLY=( $( compgen -W "$(iw | cut -d' ' -f1 | grep '^\s[^-]')" -- "$cur" ) )
33+
COMPREPLY=( $( compgen -W "commands dev event features help list phy reg wdev" -- "$cur" ) )
3034
return
3135
;;
3236
esac
3337
fi
3438

35-
if [[ $obj == help ]]; then
36-
COMPREPLY=( $(compgen -W "ap cac channels coalesce cqm del disconnect get ibss info interface link mesh mpath mpp ocb offchannel p2p reg roc scan set station survey switch vendor wowlan" -- "$cur") )
39+
if [[ $obj = help ]]; then
40+
COMPREPLY=( $(compgen -W "ap cac channels coalesce connect cqm del\
41+
disconnect get ibss info interface link mesh mpath mpp ocb \
42+
offchannel p2p reg roc scan set station survey switch vendor \
43+
wowlan" -- "$cur") )
3744
return
3845
fi
3946

4047
case $obj in
4148
dev)
42-
if [[ $prev == dev ]]; then
49+
if [[ $prev = dev ]]; then
4350
_available_interfaces
4451
return
52+
elif [[ -z $cmd ]]; then
53+
COMPREPLY=( $(compgen -W "ap cac connect cqm del \
54+
disconnect get ibss info interface link mesh mpath mpp\
55+
ocb offchannel roc scan set station survey switch \
56+
vendor" -- "$cur") )
57+
return
58+
elif [[ $prev = $cmd ]]; then
59+
case $cmd in
60+
ap)
61+
COMPREPLY=( $(compgen -W "start stop" -- "$cur") )
62+
;;
63+
cac)
64+
COMPREPLY=( $(compgen -W "channel freq trigger" -- "$cur") )
65+
;;
66+
cqm)
67+
COMPREPLY=( $(compgen -W "rssi" -- "$cur") )
68+
;;
69+
del)
70+
return
71+
;;
72+
disconnect)
73+
return
74+
;;
75+
get)
76+
COMPREPLY=( $(compgen -W "mesh_param power_save" -- "$cur") )
77+
;;
78+
ibss)
79+
COMPREPLY=( $(compgen -W "join leave" -- "$cur") )
80+
;;
81+
info)
82+
return
83+
;;
84+
interface)
85+
COMPREPLY=( $(compgen -W "add" -- "$cur") )
86+
;;
87+
link)
88+
return
89+
;;
90+
mesh)
91+
COMPREPLY=( $(compgen -W "join leave" -- "$cur") )
92+
;;
93+
mpath)
94+
COMPREPLY=( $(compgen -W "del dump get new set" -- "$cur") )
95+
;;
96+
mpp)
97+
COMPREPLY=( $(compgen -W "dump get" -- "$cur") )
98+
;;
99+
ocb)
100+
COMPREPLY=( $(compgen -W "join leave" -- "$cur") )
101+
;;
102+
offchannel)
103+
return
104+
;;
105+
roc)
106+
COMPREPLY=( $(compgen -W "start" -- "$cur") )
107+
;;
108+
scan)
109+
COMPREPLY=( $(compgen -W "abort dump sched_stop" -- "$cur") )
110+
;;
111+
set)
112+
COMPREPLY=( $(compgen -W "4addr channel freq mcast_rate meshid mesh_param monitor noack_map peer power_save txpower type" -- "$cur") )
113+
;;
114+
station)
115+
COMPREPLY=( $(compgen -W "del dump get set" -- "$cur") )
116+
;;
117+
survey)
118+
COMPREPLY=( $(compgen -W "dump" -- "$cur") )
119+
;;
120+
switch)
121+
COMPREPLY=( $(compgen -W "channel freq" -- "$cur") )
122+
;;
123+
vendor)
124+
COMPREPLY=( $(compgen -W "recv recvbin send" -- "$cur") )
125+
;;
126+
esac
127+
else
128+
case $cmd in
129+
cac)
130+
case $prev in
131+
channel)
132+
;;
133+
freq)
134+
if [[ $prev = freq ]]; then
135+
COMPREPLY=( $(compgen -W "chanel freq" -- "$cur") )
136+
return
137+
fi
138+
;;
139+
trigger)
140+
;;
141+
esac
142+
;;
143+
get)
144+
if [[ ${words[subcword+1]} = "mesh_param" ]]; then
145+
COMPREPLY=( $(compgen -W "$(${words[@]:0:cword}|sed -n '/\s\+-\s\+/{s/\s\+-\s\+//;p}')" -- "$cur" ) )
146+
fi
147+
;;
148+
interface)
149+
case $((cword-subcword)) in
150+
2)
151+
COMPREPLY=( $(compgen -W "type" -- "$cur") )
152+
;;
153+
3)
154+
COMPREPLY=( $(compgen -W "none fcsfail control otherbss cook active mumimo-groupid mumimo-follow-mac" -- "$cur") )
155+
;;
156+
4)
157+
COMPREPLY=( $(compgen -W "mesh_id 4addr flags addr" -- "$cur") )
158+
;;
159+
esac
160+
;;
161+
set)
162+
local c
163+
case ${words[subcword+1]} in
164+
4addr)
165+
c="on off"
166+
;;
167+
channel)
168+
if [[ $prev != "channel" ]]; then
169+
c="NOHT HT20 HT40+ HT40- 5MHz 10MHz 80MHz"
170+
fi
171+
;;
172+
freq)
173+
#TODO
174+
;;
175+
mesh_param)
176+
if [[ $prev = mesh_param ]]; then
177+
COMPREPLY=( $(compgen -W "$(${words[@]:0:cword}|sed -n '/\s\+-\s\+/{s/\s\+-\s\+//;p}')" -- "$cur" ) )
178+
return
179+
fi
180+
;;
181+
monitor)
182+
COMPREPLY=( $(compgen -W "none fcsfail control otherbss cook active mumimo-groupid mumimo-follow-mac" -- "$cur") )
183+
;;
184+
power_save)
185+
COMPREPLY=( $(compgen -W "on off" -- "$cur" ) )
186+
;;
187+
txpower)
188+
COMPREPLY=( $(compgen -W "auto fixed limit" -- "$cur") )
189+
;;
190+
type)
191+
COMPREPLY=( $(compgen -W "managed ibss monitor mesh wds" -- "$cur") )
192+
;;
193+
esac
194+
;;
195+
station)
196+
case ${words[subcword+1]} in
197+
set)
198+
case $((cword-subcword)) in
199+
2)
200+
COMPREPLY=( $(compgen -W "mesh_power_mode vlan plink_action" -- "$cur") )
201+
;;
202+
3)
203+
case $prev in
204+
mesh_power_mode)
205+
COMPREPLY=( $(compgen -W "active light deep" -- "$cur") )
206+
;;
207+
plink_action)
208+
COMPREPLY=( $(compgen -W "open block" -- "$cur") )
209+
;;
210+
esac
211+
;;
212+
esac
213+
;;
214+
del)
215+
if [[ cword-subcword -eq 2 ]]; then
216+
COMPREPLY=( $(compgen -W "subtype reason-code" -- "$cur"))
217+
fi
218+
esac
219+
;;
220+
esac
45221
fi
46-
case $(($cword-$subcword)) in
47-
1)
48-
COMPREPLY=( $(compgen -W "ap cac cqm del disconnect get ibss info interface link mesh mpath mpp ocb offchannel roc scan set station survey switch vendor" -- "$cur") )
49-
;;
50-
2)
51-
case $prev in
52-
ap)
53-
COMPREPLY=( $(compgen -W "start stop" -- "$cur") )
54-
;;
55-
cac)
56-
COMPREPLY=( $(compgen -W "channel freq trigger" -- "$cur") )
57-
;;
58-
cqm)
59-
COMPREPLY=( $(compgen -W "rssi" -- "$cur") )
60-
;;
61-
del)
62-
# TODO
63-
;;
64-
disconnect)
65-
;;
66-
get)
67-
COMPREPLY=( $(compgen -W "mesh_param power_save" -- "$cur") )
68-
;;
69-
ibss)
70-
COMPREPLY=( $(compgen -W "leave" -- "$cur") )
71-
;;
72-
info)
73-
return
74-
;;
75-
interface)
76-
COMPREPLY=( $(compgen -W "add" -- "$cur") )
77-
;;
78-
link)
79-
return
80-
;;
81-
mesh)
82-
COMPREPLY=( $(compgen -W "join leave" -- "$cur") )
83-
;;
84-
mpath)
85-
COMPREPLY=( $(compgen -W "del dump get new set" -- "$cur") )
86-
;;
87-
mpp)
88-
COMPREPLY=( $(compgen -W "dump get" -- "$cur") )
89-
;;
90-
ocb)
91-
COMPREPLY=( $(compgen -W "join leave" -- "$cur") )
92-
;;
93-
offchannel)
94-
# TODO
95-
;;
96-
roc)
97-
COMPREPLY=( $(compgen -W "start" -- "$cur") )
98-
;;
99-
scan)
100-
COMPREPLY=( $(compgen -W "abort dump sched_stop" -- "$cur") )
101-
;;
102-
set)
103-
# TODO
104-
COMPREPLY=( $(compgen -W "4addr channel freq mcast_rate meshid mesh_param monitor noack_map peer power_save txpower type" -- "$cur") )
105-
;;
106-
station)
107-
COMPREPLY=( $(compgen -W "del dump get set" -- "$cur") )
108-
;;
109-
survey)
110-
COMPREPLY=( $(compgen -W "dump" -- "$cur") )
111-
;;
112-
switch)
113-
COMPREPLY=( $(compgen -W "channel freq" -- "$cur") )
114-
;;
115-
vendor)
116-
COMPREPLY=( $(compgen -W "recv recvbin send" -- "$cur") )
117-
;;
118-
esac
119-
;;
120-
esac
121-
;;
222+
;;
223+
phy)
224+
if [[ $prev = phy ]]; then
225+
COMPREPLY=( $(compgen -W $(ls /sys/class/ieee80211/) -- "$cur") )
226+
return
227+
fi
228+
;;
122229
esac
123230

124-
} &&
125-
complete -F _iw iw
231+
} && complete -F _iw iw
126232

127233
# ex: filetype=sh

0 commit comments

Comments
 (0)