Skip to content

Commit

Permalink
fix(_comp_compgen_known_hosts): work around bash-4.2 nounset
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 17, 2023
1 parent 43bb8f0 commit d2860cb
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2642,21 +2642,22 @@ _comp_compgen_known_hosts__impl()
_comp_compgen -av known_hosts -- -A hostname -P "$prefix" -S "$suffix"
fi

if ((${#known_hosts[@]})); then
if [[ $ipv4 ]]; then
known_hosts=("${known_hosts[@]/*:*$suffix/}")
fi
if [[ $ipv6 ]]; then
known_hosts=("${known_hosts[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}")
fi
if [[ $ipv4 || $ipv6 ]]; then
for i in "${!known_hosts[@]}"; do
[[ ${known_hosts[i]} ]] || unset -v 'known_hosts[i]'
done
fi
_comp_compgen -v known_hosts -c "$prefix$cur" ltrim_colon "${known_hosts[@]}"
((${#known_hosts[@]})) || return 1

if [[ $ipv4 ]]; then
known_hosts=("${known_hosts[@]/*:*$suffix/}")
fi
if [[ $ipv6 ]]; then
known_hosts=("${known_hosts[@]/+([0-9]).+([0-9]).+([0-9]).+([0-9])$suffix/}")
fi
if [[ $ipv4 || $ipv6 ]]; then
for i in "${!known_hosts[@]}"; do
[[ ${known_hosts[i]} ]] || unset -v 'known_hosts[i]'
done
fi
((${#known_hosts[@]})) || return 1

_comp_compgen -v known_hosts -c "$prefix$cur" ltrim_colon "${known_hosts[@]}"
} # _comp_compgen_known_hosts__impl()
complete -F _known_hosts traceroute traceroute6 \
fping fping6 telnet rsh rlogin ftp dig drill mtr ssh-installkeys showmount
Expand Down

0 comments on commit d2860cb

Please sign in to comment.