Skip to content

Commit fe13ff3

Browse files
committed
refactor(_comp_mac_addresses): turn into a generator
1 parent 7633274 commit fe13ff3

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

bash_completion

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,16 +1450,17 @@ _comp_compgen_signals()
14501450

14511451
# This function completes on known mac addresses
14521452
#
1453-
_comp_mac_addresses()
1453+
_comp_compgen_mac_addresses()
14541454
{
14551455
local re='\([A-Fa-f0-9]\{2\}:\)\{5\}[A-Fa-f0-9]\{2\}'
14561456
local PATH="$PATH:/sbin:/usr/sbin"
1457+
local -a addresses
14571458

14581459
# Local interfaces
14591460
# - ifconfig on Linux: HWaddr or ether
14601461
# - ifconfig on FreeBSD: ether
14611462
# - ip link: link/ether
1462-
_comp_split -a COMPREPLY "$(
1463+
_comp_compgen -v addresses split -- "$(
14631464
{
14641465
LC_ALL=C ifconfig -a || ip -c=never link show || ip link show
14651466
} 2>/dev/null | command sed -ne \
@@ -1470,7 +1471,7 @@ _comp_mac_addresses()
14701471
)"
14711472

14721473
# ARP cache
1473-
_comp_split -a COMPREPLY "$(
1474+
_comp_compgen -av addresses split -- "$(
14741475
{
14751476
arp -an || ip -c=never neigh show || ip neigh show
14761477
} 2>/dev/null | command sed -ne \
@@ -1479,12 +1480,10 @@ _comp_mac_addresses()
14791480
)"
14801481

14811482
# /etc/ethers
1482-
_comp_split -a COMPREPLY "$(command sed -ne \
1483+
_comp_compgen -av addresses split -- "$(command sed -ne \
14831484
"s/^[[:space:]]*\($re\)[[:space:]].*/\1/p" /etc/ethers 2>/dev/null)"
14841485

1485-
((${#COMPREPLY[@]})) &&
1486-
_comp_compgen -- -W '"${COMPREPLY[@]}"'
1487-
_comp_ltrim_colon_completions "$cur"
1486+
_comp_compgen_ltrim_colon "${addresses[@]}"
14881487
}
14891488

14901489
# This function completes on configured network interfaces

bash_completion.d/000_bash_completion_compat.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _comp_deprecate_func 2.12 _get_comp_words_by_ref _comp_get_words
1313
_comp_deprecate_func 2.12 _longopt _comp_longopt
1414
_comp_deprecate_func 2.12 __ltrim_colon_completions _comp_ltrim_colon_completions
1515
_comp_deprecate_func 2.12 _signals _comp_compgen_signals
16-
_comp_deprecate_func 2.12 _mac_addresses _comp_mac_addresses
16+
_comp_deprecate_func 2.12 _mac_addresses _comp_compgen_mac_addresses
1717
_comp_deprecate_func 2.12 _available_interfaces _comp_available_interfaces
1818
_comp_deprecate_func 2.12 _configured_interfaces _comp_configured_interfaces
1919
_comp_deprecate_func 2.12 _ip_addresses _comp_ip_addresses

completions/ether-wake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _comp_cmd_ether_wake()
2121
return
2222
fi
2323

24-
_comp_mac_addresses
24+
_comp_compgen_mac_addresses
2525
} &&
2626
complete -F _comp_cmd_ether_wake ether-wake etherwake
2727

completions/wol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ _comp_cmd_wol()
3838
return
3939
fi
4040

41-
_comp_mac_addresses
41+
_comp_compgen_mac_addresses
4242
} &&
4343
complete -F _comp_cmd_wol wol
4444

0 commit comments

Comments
 (0)