Skip to content

Commit

Permalink
fix: prefer using iproute2 instead of ifconfig
Browse files Browse the repository at this point in the history
For `_comp_compgen_available_interfaces`, we prefer to use ip
(iproute) since long interface names will be truncated by ifconfig
(respective packages in the operating system, e.g. inetutils) [1].
Even for the other functions that use "ifconfig" and "ip", we change
to use `ip` because `ip`'s behavior is more uniform among the systems
and also `ip` is becoming more common in Linux distributions.

[1]: https://github.com/scop/bash-completion/pull/1090/files

Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
  • Loading branch information
hellodword and akinomyoga committed May 13, 2024
1 parent 0543d1a commit 962e9ca
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,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 @@ -1697,7 +1697,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
} 2>/dev/null |
command sed -e 's/[[:space:]]addr:/ /' -ne \
"s|.*inet${_n}[[:space:]]\{1,\}\([^[:space:]/]*\).*|\1|p")" ||
Expand Down Expand Up @@ -1731,9 +1731,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 inetutils (ifconfig) 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

0 comments on commit 962e9ca

Please sign in to comment.