Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prefer using iproute2 instead of ifconfig #1090

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ _comp_compgen_mac_addresses()
# - ip link: link/ether
_comp_compgen -v addresses split -- "$(
{
LC_ALL=C ifconfig -a || ip -c=never link show || ip link show
ip -c=never link show || ip link show || LC_ALL=C ifconfig -a
} 2>/dev/null | command sed -ne \
"s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($_re\)[[:space:]].*/\1/p" -ne \
"s/.*[[:space:]]HWaddr[[:space:]]\{1,\}\($_re\)[[:space:]]*$/\1/p" -ne \
Expand Down Expand Up @@ -1699,7 +1699,7 @@ _comp_compgen_ip_addresses()
local PATH=$PATH:/sbin
local addrs
_comp_compgen -v addrs split -- "$({
LC_ALL=C ifconfig -a || ip -c=never addr show || ip addr show
ip -c=never addr show || ip addr show || LC_ALL=C ifconfig -a
akinomyoga marked this conversation as resolved.
Show resolved Hide resolved
} 2>/dev/null |
command sed -e 's/[[:space:]]addr:/ /' -ne \
"s|.*inet${_n}[[:space:]]\{1,\}\([^[:space:]/]*\).*|\1|p")" ||
Expand Down Expand Up @@ -1733,9 +1733,12 @@ _comp_compgen_available_interfaces()
if [[ ${1-} == -w ]]; then
iwconfig
elif [[ ${1-} == -a ]]; then
ifconfig || ip -c=never link show up || ip link show up
# Note: we prefer ip (iproute2) to ifconfig (inetutils) since long
# interface names will be truncated by ifconfig [1].
# [1]: https://github.com/scop/bash-completion/issues/1089
ip -c=never link show up || ip link show up || ifconfig
else
ifconfig -a || ip -c=never link show || ip link show
ip -c=never link show || ip link show || ifconfig -a
fi
} 2>/dev/null | _comp_awk \
'/^[^ \t]/ { if ($1 ~ /^[0-9]+:/) { print $2 } else { print $1 } }')" &&
Expand Down
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions test/fixtures/shared/bin/ip
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

# Dummy "ip addr show" and "ip link show up" emulator

for arg in "$@"; do
case "$arg" in
link)
cat <<EOF
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
link/ether 33:33:33:33:33:33 brd ff:ff:ff:ff:ff:ff link-netnsid 0
EOF
exit 0
;;
addr)
cat <<EOF
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 33:33:33:33:33:33 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.80.11/24 brd 192.168.80.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::000:0000:0000:0000/64 scope link
valid_lft forever preferred_lft forever
EOF
exit 0
;;
esac
done

exit 1
2 changes: 1 addition & 1 deletion test/t/unit/test_unit_compgen_xinetd_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_env_non_pollution(self, bash):
def test_basic(self, bash):
output = assert_bash_exec(
bash,
"foo() { local _comp__test_xinetd_dir=$PWD/shared/bin; unset -v COMPREPLY; "
"foo() { local _comp__test_xinetd_dir=$PWD/_comp_compgen_xinetd_services/xinetd.d; unset -v COMPREPLY; "
'_comp_compgen_xinetd_services; printf "%s\\n" "${COMPREPLY[@]}"; }; foo; unset -f foo',
want_output=True,
)
Expand Down