Skip to content

Commit 93b591c

Browse files
committed
Bash completion now working under FreeBSD.
1 parent 14261ae commit 93b591c

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/subnetcalc.bash-completion

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,34 @@ _example_program1()
2222
{
2323
# Based on: https://www.benningtons.net/index.php/bash-completion/
2424
local cur prev words cword
25-
_init_completion || return
25+
if type -t _comp_initialize >/dev/null; then
26+
_comp_initialize || return
27+
elif type -t _init_completion >/dev/null; then
28+
_init_completion || return
29+
else
30+
# Manual initialization for older bash completion versions:
31+
COMPREPLY=()
32+
cur="${COMP_WORDS[COMP_CWORD]}"
33+
prev="${COMP_WORDS[COMP_CWORD-1]}"
34+
words="${COMP_WORDS}"
35+
cword="${COMP_CWORD}"
36+
fi
2637

2738
# echo "cur=$cur prev=$prev words=${words[@]} cword=$cword"
2839
# echo ""
2940

3041
# ====== Parameters ======================================================
3142
if [ $cword -le 1 ] ; then
32-
# Suggest examples for IP address and network:
33-
COMPREPLY=($(compgen -W "$(ip addr show | awk '/[ ]+inet/ { print $2 }')" -- "$cur"))
43+
# Suggest IP addresses of local machine:
44+
local addreses
45+
if [ -x /usr/bin/ip ] ; then
46+
addresses="$(/usr/bin/ip addr show | awk '/[ ]+inet/ { print $2 }')"
47+
elif [ -x /sbin/ifconfig ] ; then
48+
local addressesV4="$(/sbin/ifconfig | awk '/[ \t]+inet / { a=$4 ; print $2 "/" sprintf("%d.%d.%d.%d", "0x" substr(a, 3, 2), "0x" substr(a, 5, 2), "0x" substr(a, 7, 2), "0x" substr(a, 9, 2)) }')"
49+
local addressesV6="$(/sbin/ifconfig | awk '/[ \t]+inet6 / { print $2 "/" $4 }' | sed -e 's#%.*/#/#')"
50+
addresses="${addressesV4} ${addressesV6}"
51+
fi
52+
COMPREPLY=($(compgen -W "${addresses}" -- "${cur}"))
3453
return
3554
fi
3655

0 commit comments

Comments
 (0)