Skip to content

Commit a50413a

Browse files
committed
feat(ip): Check /usr/share config path
1 parent 33f789c commit a50413a

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

completions-core/ip.bash

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# ip(8) completion -*- shell-script -*-
22

3-
_comp_cmd_ip__iproute2_etc()
3+
_comp_cmd_ip__iproute2_conf()
44
{
5-
_comp_compgen -a split -- "$(_comp_awk '!/#/ { print $2 }' "/etc/iproute2/$1" \
5+
# /usr/share/iproute2/$1 is the default since iproute2 6.7.0
6+
local conf_file="/usr/share/iproute2/$1"
7+
if [[ ! -f $conf_file ]]; then
8+
# iproute2 6.5 and 6.6 used /usr/lib/iproute2/$1
9+
if [[ -f /usr/lib/iproute2/$1 ]]; then
10+
conf_file="/usr/lib/iproute2/$1"
11+
else
12+
conf_file="/etc/iproute2/$1"
13+
fi
14+
fi
15+
_comp_compgen -a split -- "$(_comp_awk '!/#/ { print $2 }' "$conf_file" \
616
2>/dev/null)"
717
}
818

@@ -165,7 +175,7 @@ _comp_cmd_ip()
165175
elif [[ $prev == dev ]]; then
166176
_comp_compgen_available_interfaces
167177
elif [[ $prev == group ]]; then
168-
_comp_cmd_ip__iproute2_etc group
178+
_comp_cmd_ip__iproute2_conf group
169179
fi
170180
;;
171181
property)
@@ -194,7 +204,7 @@ _comp_cmd_ip()
194204
_comp_compgen_available_interfaces
195205
;;
196206
scope)
197-
_comp_cmd_ip__iproute2_etc rt_scopes
207+
_comp_cmd_ip__iproute2_conf rt_scopes
198208
;;
199209
broadcast | anycast | peer | metric)
200210
:
@@ -212,7 +222,7 @@ _comp_cmd_ip()
212222
if [[ $prev == dev ]]; then
213223
_comp_compgen_available_interfaces
214224
elif [[ $prev == scope ]]; then
215-
_comp_cmd_ip__iproute2_etc rt_scopes
225+
_comp_cmd_ip__iproute2_conf rt_scopes
216226
else
217227
: # TODO
218228
fi
@@ -226,7 +236,7 @@ _comp_cmd_ip()
226236
elif [[ $prev == dev ]]; then
227237
_comp_compgen_available_interfaces
228238
elif [[ $prev == scope ]]; then
229-
_comp_cmd_ip__iproute2_etc rt_scopes
239+
_comp_cmd_ip__iproute2_conf rt_scopes
230240
elif [[ $prev == type ]]; then
231241
_comp_cmd_ip__link_types "$1"
232242
fi
@@ -263,13 +273,13 @@ _comp_cmd_ip()
263273
list | flush | save)
264274
case "$prev" in
265275
proto)
266-
_comp_cmd_ip__iproute2_etc rt_protos
276+
_comp_cmd_ip__iproute2_conf rt_protos
267277
;;
268278
table)
269279
_comp_compgen -- -W 'local main default all'
270280
;;
271281
scope)
272-
_comp_cmd_ip__iproute2_etc rt_scopes
282+
_comp_cmd_ip__iproute2_conf rt_scopes
273283
;;
274284
root | match | exact | vrf)
275285
: # TODO: Can we complete vrf?
@@ -417,7 +427,7 @@ _comp_cmd_ip()
417427
_comp_compgen_available_interfaces
418428
;;
419429
protocol)
420-
_comp_cmd_ip__iproute2_etc rt_protos
430+
_comp_cmd_ip__iproute2_conf rt_protos
421431
;;
422432
proxy)
423433
:

test/t/test_ip.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ def test_addr_type(self, completion):
6868
@pytest.mark.complete("ip -", require_cmd=True)
6969
def test_options(self, completion):
7070
assert "-family" in completion
71+
72+
@pytest.mark.complete("ip link show group ", require_cmd=True)
73+
def test_link_groups_from_file(self, completion):
74+
assert "default" in completion
75+
76+
@pytest.mark.complete("ip addr show scope ", require_cmd=True)
77+
def test_addr_scopes_from_file(self, completion):
78+
assert "host" in completion
79+
assert "global" in completion

0 commit comments

Comments
 (0)