Skip to content

Commit 3b1586b

Browse files
authored
Merge pull request #1090 from hellodword/patch-1
fix: prefer using iproute2 instead of ifconfig
2 parents d4a1c56 + c2cafae commit 3b1586b

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

bash_completion

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ _comp_compgen_mac_addresses()
17081708
# - ip link: link/ether
17091709
_comp_compgen -v addresses split -- "$(
17101710
{
1711-
LC_ALL=C ifconfig -a || ip -c=never link show || ip link show
1711+
ip -c=never link show || ip link show || LC_ALL=C ifconfig -a
17121712
} 2>/dev/null | command sed -ne \
17131713
"s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($_re\)[[:space:]].*/\1/p" -ne \
17141714
"s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($_re\)[[:space:]]*$/\1/p" -ne \
@@ -1779,7 +1779,7 @@ _comp_compgen_ip_addresses()
17791779
local PATH=$PATH:/sbin
17801780
local addrs
17811781
_comp_compgen -v addrs split -- "$({
1782-
LC_ALL=C ifconfig -a || ip -c=never addr show || ip addr show
1782+
ip -c=never addr show || ip addr show || LC_ALL=C ifconfig -a
17831783
} 2>/dev/null |
17841784
command sed -e 's/[[:space:]]addr:/ /' -ne \
17851785
"s|.*inet${_n}[[:space:]]\{1,\}\([^[:space:]/]*\).*|\1|p")" ||
@@ -1813,9 +1813,12 @@ _comp_compgen_available_interfaces()
18131813
if [[ ${1-} == -w ]]; then
18141814
iwconfig
18151815
elif [[ ${1-} == -a ]]; then
1816-
ifconfig || ip -c=never link show up || ip link show up
1816+
# Note: we prefer ip (iproute2) to ifconfig (inetutils) since long
1817+
# interface names will be truncated by ifconfig [1].
1818+
# [1]: https://github.com/scop/bash-completion/issues/1089
1819+
ip -c=never link show up || ip link show up || ifconfig
18171820
else
1818-
ifconfig -a || ip -c=never link show || ip link show
1821+
ip -c=never link show || ip link show || ifconfig -a
18191822
fi
18201823
} 2>/dev/null | _comp_awk \
18211824
'/^[^ \t]/ { if ($1 ~ /^[0-9]+:/) { print $2 } else { print $1 } }')" &&

test/fixtures/_comp_compgen_xinetd_services/xinetd.d/arp

Whitespace-only changes.

test/fixtures/_comp_compgen_xinetd_services/xinetd.d/ifconfig

Whitespace-only changes.

test/fixtures/shared/bin/ip

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
# Dummy "ip addr show" and "ip link show up" emulator
4+
5+
for arg in "$@"; do
6+
case "$arg" in
7+
link)
8+
cat <<EOF
9+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
10+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
11+
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
12+
link/ether 33:33:33:33:33:33 brd ff:ff:ff:ff:ff:ff link-netnsid 0
13+
EOF
14+
exit 0
15+
;;
16+
addr)
17+
cat <<EOF
18+
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
19+
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
20+
inet 127.0.0.1/8 scope host lo
21+
valid_lft forever preferred_lft forever
22+
inet6 ::1/128 scope host
23+
valid_lft forever preferred_lft forever
24+
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
25+
link/ether 33:33:33:33:33:33 brd ff:ff:ff:ff:ff:ff link-netnsid 0
26+
inet 192.168.80.11/24 brd 192.168.80.255 scope global eth0
27+
valid_lft forever preferred_lft forever
28+
inet6 fe80::000:0000:0000:0000/64 scope link
29+
valid_lft forever preferred_lft forever
30+
EOF
31+
exit 0
32+
;;
33+
esac
34+
done
35+
36+
exit 1

test/t/unit/test_unit_compgen_xinetd_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_env_non_pollution(self, bash):
1717
def test_basic(self, bash):
1818
output = assert_bash_exec(
1919
bash,
20-
"foo() { local _comp__test_xinetd_dir=$PWD/shared/bin; unset -v COMPREPLY; "
20+
"foo() { local _comp__test_xinetd_dir=$PWD/_comp_compgen_xinetd_services/xinetd.d; unset -v COMPREPLY; "
2121
'_comp_compgen_xinetd_services; printf "%s\\n" "${COMPREPLY[@]}"; }; foo; unset -f foo',
2222
want_output=True,
2323
)

0 commit comments

Comments
 (0)