diff options
author | dana <dana@dana.is> | 2018-06-18 17:52:36 -0500 |
---|---|---|
committer | dana <dana@dana.is> | 2018-06-18 17:52:36 -0500 |
commit | ea94f3bf140d48e33f75fb49675de12701536a5a (patch) | |
tree | 30c0f2e594a3c89f3c2c740d424bddc56874e3c1 /Completion/Unix | |
parent | b05a56a415efca547e89364314237f8bd93ca506 (diff) | |
download | zsh-ea94f3bf140d48e33f75fb49675de12701536a5a.tar.gz zsh-ea94f3bf140d48e33f75fb49675de12701536a5a.tar.xz zsh-ea94f3bf140d48e33f75fb49675de12701536a5a.zip |
43047: Make _bind_addresses always return local IPs
Diffstat (limited to 'Completion/Unix')
-rw-r--r-- | Completion/Unix/Type/_bind_addresses | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Completion/Unix/Type/_bind_addresses b/Completion/Unix/Type/_bind_addresses index 3460b7959..6042eaf1e 100644 --- a/Completion/Unix/Type/_bind_addresses +++ b/Completion/Unix/Type/_bind_addresses @@ -1,15 +1,17 @@ #autoload -local expl - -case $OSTYPE in - aix*) _hosts "$@" ;; - darwin*|freebsd*|dragonfly*) _hosts "$@" ;; - irix*) _hosts "$@" ;; - # Couldn't find anything special for linux except for /proc/net/dev - # Is there any proc file which gives the formatted ip? - linux*) ;& - *) - _wanted bind-addresses expl 'bind address' compadd "$@" - \ - ${${${(M)${(f)"$(ifconfig -a)"}:#*addr:*}##*addr:( |)}%%(/| )*} -esac +# @todo In the future it might be useful to have this function take a glob or +# similar to filter out loop-back addresses, only return IPv4/6, etc. + +local -a expl tmp cmd=( ifconfig -a ) + +# A lot of Linux systems have ifconfig, but this is probably safer (and it's +# parsed the same way) +[[ $OSTYPE == linux* ]] && (( $+commands[ip] )) && cmd=( ip addr show ) + +tmp=( ${(f)"$( _call_program bind-addresses $cmd )"} ) +tmp=( ${(@M)tmp##(|[[:space:]]##)inet(|6)(|:)[[:space:]]*} ) +tmp=( ${(@)tmp#*inet(|6)(|:)[[:space:]]##} ) +tmp=( ${(@)tmp%%[^0-9A-Fa-f:.]*} ) + +_wanted bind-addresses expl 'bind address' compadd -a "$@" - tmp |