Skip to content

Commit 4cb3cf7

Browse files
committed
iw: New completion
1 parent 8ef547a commit 4cb3cf7

File tree

3 files changed

+334
-0
lines changed

3 files changed

+334
-0
lines changed

completions/iw

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
# iw(8) completion -*- shell-script -*-
2+
3+
_iw()
4+
{
5+
local cur prev words cword
6+
_init_completion || return
7+
8+
local subcword obj cmd
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
22+
[[ "${words[subcword]}" != -* ]] && obj=${words[subcword]}
23+
done
24+
25+
if [[ -z $obj ]]; then
26+
case $cur in
27+
-*)
28+
local c='--version --debug'
29+
COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
30+
return
31+
;;
32+
*)
33+
COMPREPLY=( $( compgen -W 'commands dev event features help
34+
list phy reg wdev' -- "$cur" ) )
35+
return
36+
;;
37+
esac
38+
fi
39+
40+
if [[ $obj == help ]]; then
41+
COMPREPLY=( $( compgen -W 'ap cac channels coalesce connect cqm del
42+
dev disconnect get ibss info interface link mesh mpath mpp ocb
43+
offchannel phy p2p reg roc scan set station survey switch vendor
44+
wowlan' -- "$cur") )
45+
return
46+
fi
47+
48+
case $obj in
49+
dev)
50+
if [[ $prev == dev ]]; then
51+
_available_interfaces
52+
return
53+
elif [[ -z $cmd ]]; then
54+
COMPREPLY=( $( compgen -W 'ap cac connect cqm del
55+
disconnect get ibss info interface link mesh mpath mpp
56+
ocb offchannel roc scan set station survey switch
57+
vendor' -- "$cur") )
58+
return
59+
elif [[ $prev == $cmd ]]; then
60+
case $cmd in
61+
ap)
62+
COMPREPLY=( $( compgen -W 'start stop' -- "$cur" ) )
63+
return
64+
;;
65+
cac)
66+
COMPREPLY=( $( compgen -W 'channel freq trigger'
67+
-- "$cur" ) )
68+
return
69+
;;
70+
cqm)
71+
COMPREPLY=( $( compgen -W 'rssi' -- "$cur" ) )
72+
return
73+
;;
74+
del)
75+
return
76+
;;
77+
disconnect)
78+
return
79+
;;
80+
get)
81+
COMPREPLY=( $( compgen -W 'mesh_param power_save'
82+
-- "$cur" ) )
83+
return
84+
;;
85+
ibss)
86+
COMPREPLY=( $( compgen -W 'join leave' -- "$cur" ) )
87+
return
88+
;;
89+
info)
90+
return
91+
;;
92+
interface)
93+
COMPREPLY=( $( compgen -W 'add' -- "$cur" ) )
94+
return
95+
;;
96+
link)
97+
return
98+
;;
99+
mesh)
100+
COMPREPLY=( $( compgen -W 'join leave' -- "$cur" ) )
101+
return
102+
;;
103+
mpath)
104+
COMPREPLY=( $( compgen -W 'del dump get new set'
105+
-- "$cur" ) )
106+
return
107+
;;
108+
mpp)
109+
COMPREPLY=( $( compgen -W 'dump get' -- "$cur" ) )
110+
return
111+
;;
112+
ocb)
113+
COMPREPLY=( $( compgen -W 'join leave' -- "$cur" ) )
114+
return
115+
;;
116+
offchannel)
117+
return
118+
;;
119+
roc)
120+
COMPREPLY=( $( compgen -W 'start' -- "$cur" ) )
121+
return
122+
;;
123+
scan)
124+
COMPREPLY=( $( compgen -W 'abort dump sched_stop'
125+
-- "$cur" ) )
126+
return
127+
;;
128+
set)
129+
COMPREPLY=( $( compgen -W '4addr channel freq
130+
mcast_rate meshid mesh_param monitor noack_map
131+
peer power_save txpower type' -- "$cur" ) )
132+
return
133+
;;
134+
station)
135+
COMPREPLY=( $( compgen -W 'del dump get set'
136+
-- "$cur" ) )
137+
return
138+
;;
139+
survey)
140+
COMPREPLY=( $( compgen -W 'dump' -- "$cur" ) )
141+
return
142+
;;
143+
switch)
144+
COMPREPLY=( $( compgen -W 'channel freq' -- "$cur" ) )
145+
return
146+
;;
147+
vendor)
148+
COMPREPLY=( $( compgen -W 'recv recvbin send'
149+
-- "$cur" ) )
150+
return
151+
;;
152+
esac
153+
else
154+
case $cmd in
155+
cac)
156+
case $prev in
157+
channel)
158+
;;
159+
freq)
160+
if [[ $prev == freq ]]; then
161+
COMPREPLY=( $( compgen -W 'chanel freq'
162+
-- "$cur" ) )
163+
return
164+
fi
165+
;;
166+
trigger)
167+
return
168+
;;
169+
esac
170+
;;
171+
get)
172+
if [[ "${words[subcword+1]}" == 'mesh_param' ]]; then
173+
COMPREPLY=( $( compgen -W "$( "${words[@]:0:cword}"
174+
sed -n '/\s\+-\s\+/{s/\s\+-\s\+//;p}' )"
175+
-- "$cur" ) )
176+
fi
177+
;;
178+
interface)
179+
case "$(( cword-subcword ))" in
180+
2)
181+
COMPREPLY=( $( compgen -W 'type' -- "$cur" ) )
182+
return
183+
;;
184+
3)
185+
COMPREPLY=( $( compgen -W 'none fcsfail control
186+
otherbss cook active mumimo-groupid
187+
mumimo-follow-mac' -- "$cur" ) )
188+
return
189+
;;
190+
4)
191+
COMPREPLY=( $( compgen -W 'mesh_id 4addr flags
192+
addr' -- "$cur" ) )
193+
return
194+
;;
195+
esac
196+
;;
197+
set)
198+
local c
199+
case "${words[subcword+1]}" in
200+
4addr)
201+
c='on off'
202+
;;
203+
channel)
204+
if [[ $prev != 'channel' ]]; then
205+
c='NOHT HT20 HT40+ HT40- 5MHz 10MHz 80MHz'
206+
fi
207+
;;
208+
freq)
209+
#TODO
210+
;;
211+
mesh_param)
212+
if [[ $prev == mesh_param ]]; then
213+
COMPREPLY=( $( compgen -W "$(
214+
"${words[@]:0:cword}" | sed -n '/\s\+-\s\+/{s/\s\+-\s\+//;p}' )" -- "$cur" ) )
215+
fi
216+
return
217+
;;
218+
monitor)
219+
COMPREPLY=( $( compgen -W 'none fcsfail control
220+
otherbss cook active mumimo-groupid
221+
mumimo-follow-mac' -- "$cur" ) )
222+
return
223+
;;
224+
power_save)
225+
COMPREPLY=( $( compgen -W 'on off'
226+
-- "$cur" ) )
227+
return
228+
;;
229+
txpower)
230+
COMPREPLY=( $( compgen -W 'auto fixed limit'
231+
-- "$cur" ) )
232+
return
233+
;;
234+
type)
235+
COMPREPLY=( $( compgen -W 'managed ibss monitor
236+
mesh wds' -- "$cur" ) )
237+
return
238+
;;
239+
esac
240+
;;
241+
station)
242+
case "${words[subcword+1]}" in
243+
set)
244+
case "$(( cword-subcword ))" in
245+
2)
246+
COMPREPLY=( $( compgen -W
247+
'mesh_power_mode vlan plink_action'
248+
-- "$cur" ) )
249+
return
250+
;;
251+
3)
252+
case $prev in
253+
mesh_power_mode)
254+
COMPREPLY=( $( compgen -W
255+
'active light deep'
256+
-- "$cur" ) )
257+
return
258+
;;
259+
plink_action)
260+
COMPREPLY=( $( compgen -W
261+
'open block' -- "$cur" ) )
262+
return
263+
;;
264+
esac
265+
;;
266+
esac
267+
;;
268+
del)
269+
if [[ cword-subcword -eq 2 ]]; then
270+
COMPREPLY=( $( compgen -W 'subtype
271+
reason-code' -- "$cur" ) )
272+
fi
273+
esac
274+
;;
275+
esac
276+
fi
277+
;;
278+
phy)
279+
if [[ $prev == phy ]]; then
280+
COMPREPLY=( $( compgen -W $( ls /sys/class/ieee80211/ )
281+
-- "$cur" ) )
282+
return
283+
elif [[ -z $cmd ]]; then
284+
COMPREPLY=( $( compgen -W 'channels coalesce info interface
285+
reg set wowlan' -- "$cur" ) )
286+
return
287+
elif [[ $prev == $cmd ]]; then
288+
case $cmd in
289+
channels)
290+
return
291+
;;
292+
coalesce)
293+
COMPREPLY=( $( compgen -W 'disable enable show'
294+
-- "$cur" ) )
295+
return
296+
;;
297+
info)
298+
return
299+
;;
300+
interface)
301+
COMPREPLY=( $( compgen -W 'add' -- "$cur" ) )
302+
return
303+
;;
304+
reg)
305+
COMPREPLY=( $( compgen -W 'get' -- "$cur" ) )
306+
return
307+
;;
308+
set)
309+
COMPREPLY=( $( compgen -W 'antenna channel coverage
310+
distance frag freq name netns retry rts txpower'
311+
-- "$cur" ) )
312+
return
313+
;;
314+
wowlan)
315+
COMPREPLY=( $( compgen -W 'disable enable show'
316+
-- "$cur" ) )
317+
return
318+
;;
319+
esac
320+
fi
321+
;;
322+
esac
323+
324+
} && complete -F _iw iw
325+
326+
# ex: filetype=sh

test/t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ EXTRA_DIST = \
258258
test_iscsiadm.py \
259259
test_isort.py \
260260
test_isql.py \
261+
test_iw.py \
261262
test_iwconfig.py \
262263
test_iwlist.py \
263264
test_iwpriv.py \

test/t/test_iw.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
3+
4+
class TestIw:
5+
@pytest.mark.complete("iw ", require_cmd=True)
6+
def test_1(self, completion):
7+
assert all(x in completion for x in "commands dev event features help list phy reg wdev".split())

0 commit comments

Comments
 (0)