summary refs log tree commit diff
path: root/Completion/Unix/Type/_bind_addresses
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Unix/Type/_bind_addresses')
-rw-r--r--Completion/Unix/Type/_bind_addresses28
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