Skip to content

Commit 4f9ad00

Browse files
authored
Merge pull request #1130 from yedayak/ip-link-types
Complete ip link types
2 parents c8920c5 + f3a9be3 commit 4f9ad00

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

completions/ip

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ _comp_cmd_ip__netns()
1515
)"
1616
}
1717

18+
_comp_cmd_ip__link_types()
19+
{
20+
_comp_compgen_split -- "$(
21+
{
22+
${1-ip} -c=never link help || ${1-ip} link help
23+
} 2>&1 | command sed -e \
24+
'/TYPE := /,/}/!d' -e \
25+
's/.*{//' -e \
26+
's/}.*//' -e \
27+
's/|/ /g'
28+
)"
29+
}
30+
1831
_comp_cmd_ip()
1932
{
2033
local cur prev words cword comp_args
@@ -87,19 +100,12 @@ _comp_cmd_ip()
87100
# TODO
88101
;;
89102
delete)
90-
case $((cword - subcword)) in
91-
1)
92-
_comp_compgen_available_interfaces
93-
;;
94-
2)
95-
_comp_compgen -- -W 'type'
96-
;;
97-
3)
98-
[[ $prev == type ]] &&
99-
_comp_compgen -- -W 'vlan veth vcan dummy ifb
100-
macvlan can'
101-
;;
102-
esac
103+
if [[ $prev == type ]]; then
104+
_comp_cmd_ip__link_types "$1"
105+
else
106+
_comp_compgen_available_interfaces
107+
_comp_compgen -a -- -W 'type'
108+
fi
103109
;;
104110
set)
105111
if ((cword - subcword == 1)); then
@@ -164,11 +170,13 @@ _comp_cmd_ip()
164170
_comp_compgen_available_interfaces
165171
_comp_compgen -a -- -W 'dev scope to label dynamic
166172
permanent tentative deprecated dadfailed temporary
167-
primary secondary up'
173+
primary secondary up type'
168174
elif [[ $prev == dev ]]; then
169175
_comp_compgen_available_interfaces
170176
elif [[ $prev == scope ]]; then
171177
_comp_cmd_ip__iproute2_etc rt_scopes
178+
elif [[ $prev == type ]]; then
179+
_comp_cmd_ip__link_types "$1"
172180
fi
173181
;;
174182
*)

test/t/test_ip.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ def test_monitor(self, completion):
2727
def test_netconf(self, completion):
2828
assert "show" in completion
2929

30+
@pytest.mark.complete(
31+
"ip addr show type ",
32+
require_cmd=True,
33+
skipif="ip link help 2>/dev/null; (( $? != 255 ))",
34+
)
35+
def test_addr_type(self, completion):
36+
assert "bridge" in completion
37+
3038
@pytest.mark.complete("ip -", require_cmd=True)
3139
def test_options(self, completion):
3240
assert "-family" in completion

0 commit comments

Comments
 (0)