zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _sockstat: minor improvements
@ 2015-11-02  3:30 Eric Cook
  0 siblings, 0 replies; only message in thread
From: Eric Cook @ 2015-11-02  3:30 UTC (permalink / raw)
  To: zsh-workers

allow -p, -P and -f's argument to be completed in the same word.

Complete -P's argument using /etc/protocols again, while allowing a
comma delimited list of protocols.
---
 Completion/BSD/Command/_sockstat | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/Completion/BSD/Command/_sockstat b/Completion/BSD/Command/_sockstat
index 1b11ba4..daad946 100644
--- a/Completion/BSD/Command/_sockstat
+++ b/Completion/BSD/Command/_sockstat
@@ -1,5 +1,6 @@
 #compdef sockstat
-local -a args
+local -a args protocols
+local proto
 
 case $OSTYPE in
   *bsd*)
@@ -8,27 +9,37 @@ case $OSTYPE in
       '-6[show AF_INET6 (IPv6) sockets]'
       '-c[show connected sockets]'
       '-l[show listening sockets]'
-      '*-p[specify port number]:port numbers (comma delimited)'
+      '*-p+[specify port number]:port numbers (comma delimited)'
       '-u[show AF_LOCAL (UNIX) sockets]'
     )
   ;|
   freebsd*)
+    for proto in ${${(M)${(f)"$(</etc/protocols)"}##[a-z0-9]*}}; do
+      case $proto in
+        *\#*)
+          protocols+=(${${${(j: :)${(q)=proto}}// *\# /\[}/%/\]})
+        ;;
+        *)
+          protocols+=(${${(j: :)${=proto}}// */})
+      esac
+    done
+
     args+=(
       '*-j[show sockets belonging to JID]: : _jails -0 -o jid'
       '-L[exclude loopback]'
-      '*-P[specify protocol]: :_sequence -s , _ports'
+      '*-P+[specify protocol]: : _values -s , protocols $protocols'
     )
   ;;
   netbsd*)
     args+=(
-      '*-f[only show specified address family]:address family:(inet inet6 local unix)'
+      '*-f+[only show specified address family]:address family:(inet inet6 local unix)'
       '-n[no symbolic names for addresses/ports]'
     )
   ;;
 esac
 
 if (( $#args )); then
-  _arguments -s -w $args
+  _arguments -s -w : $args
   return
 fi
 
-- 
2.6.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-11-02  3:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-02  3:30 [PATCH] _sockstat: minor improvements Eric Cook

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).