From 96ea5e32b442ff2406f1d7268cccdd73baf313ea Mon Sep 17 00:00:00 2001 From: dana Date: Tue, 31 Jul 2018 20:46:09 -0500 Subject: 43207: Improve _bind_addresses, _php Minor change from the patch as posted to the ML: _php now calls _bind_addresses with -K, since it can't actually listen on a link-local address. --- Completion/Unix/Type/_bind_addresses | 37 ++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'Completion/Unix/Type') diff --git a/Completion/Unix/Type/_bind_addresses b/Completion/Unix/Type/_bind_addresses index 6042eaf1e..d12727800 100644 --- a/Completion/Unix/Type/_bind_addresses +++ b/Completion/Unix/Type/_bind_addresses @@ -1,9 +1,21 @@ #autoload -# @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. +# Complete locally bound IP addresses +# +# Options: +# -0 Return also `0.0.0.0` and `::` +# -4 Return only IPv4 addresses +# -6 Return only IPv6 addresses +# -b Return IPv6 addresses in brackets (for use with port numbers) +# -h Return also `localhost` +# -L Exclude loop-back addresses (`127.0.0.0/8` and `::1`) +# -K Exclude link-local addresses (`169.254.0.0/16` and `fe80::/10`) +local MATCH MBEGIN MEND local -a expl tmp cmd=( ifconfig -a ) +local -A opts + +zparseopts -A opts -D -E -- 0 4 6 b h L K # A lot of Linux systems have ifconfig, but this is probably safer (and it's # parsed the same way) @@ -14,4 +26,25 @@ tmp=( ${(@M)tmp##(|[[:space:]]##)inet(|6)(|:)[[:space:]]*} ) tmp=( ${(@)tmp#*inet(|6)(|:)[[:space:]]##} ) tmp=( ${(@)tmp%%[^0-9A-Fa-f:.]*} ) +# The order of operations here is significant +(( $+opts[-0] )) && tmp+=( 0.0.0.0 :: ) + +if (( $+opts[-6] )); then + tmp=( ${(@M)tmp:#*:*} ) +elif (( $+opts[-4] )); then + tmp=( ${(@)tmp:#*:*} ) +fi + +(( $+opts[-L] )) && { + tmp=( ${(@)tmp:#127.*} ) + tmp=( ${(@)tmp:#[0:]##:1} ) +} +(( $+opts[-K] )) && { + tmp=( ${(@)tmp:#169.254.*} ) + tmp=( ${(@)tmp:#(#i)fe[89ab]?:*} ) +} + +(( $+opts[-b] )) && tmp=( ${(@)tmp/(#m)*:*/\[$MATCH\]} ) +(( $+opts[-h] )) && tmp+=( localhost ) + _wanted bind-addresses expl 'bind address' compadd -a "$@" - tmp -- cgit 1.4.1