diff --git a/bash_completion b/bash_completion index 36a9fa890f3..a6b707e9f58 100644 --- a/bash_completion +++ b/bash_completion @@ -1708,7 +1708,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 \ @@ -1779,7 +1779,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")" || @@ -1813,9 +1813,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 } }')" && diff --git a/test/fixtures/_comp_compgen_xinetd_services/xinetd.d/arp b/test/fixtures/_comp_compgen_xinetd_services/xinetd.d/arp new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/fixtures/_comp_compgen_xinetd_services/xinetd.d/ifconfig b/test/fixtures/_comp_compgen_xinetd_services/xinetd.d/ifconfig new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/fixtures/shared/bin/ip b/test/fixtures/shared/bin/ip new file mode 100755 index 00000000000..d17490ec3d2 --- /dev/null +++ b/test/fixtures/shared/bin/ip @@ -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 < 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: 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 < 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: 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 diff --git a/test/t/unit/test_unit_compgen_xinetd_services.py b/test/t/unit/test_unit_compgen_xinetd_services.py index fdc9b3f618f..915e1895717 100644 --- a/test/t/unit/test_unit_compgen_xinetd_services.py +++ b/test/t/unit/test_unit_compgen_xinetd_services.py @@ -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, )