diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | Completion/Unix/Type/_bind_addresses | 28 |
2 files changed, 19 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog index 4fe090e10..1b9e15063 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2018-06-18 dana <dana@dana.is> + + * 43047: Completion/Unix/Type/_bind_addresses: Always return local IPs + 2018-06-18 Peter Stephenson <p.stephenson@samsung.com> * unposted: Test/V01zmodload.ztst: updated for 43039. 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 |