zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: complete services in _fuser
@ 2005-04-01 19:34 Oliver Kiddle
  0 siblings, 0 replies; only message in thread
From: Oliver Kiddle @ 2005-04-01 19:34 UTC (permalink / raw)
  To: Zsh workers

The psmisc (Linux) version of fuser can take network services as a
parameter, showing processes with network connections open. This patch
makes _fuser handle that. You need to be root for it to work so unless
'-n tcp' is specified, it doesn't affect completion for non root users.

Oliver

Index: _fuser
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_fuser,v
retrieving revision 1.3
diff -u -r1.3 _fuser
--- _fuser	22 Mar 2005 20:05:36 -0000	1.3
+++ _fuser	1 Apr 2005 19:27:44 -0000
@@ -1,8 +1,32 @@
 #compdef fuser
 
 local -a args arg1
+typeset -A opt_args
 
 if _pick_variant -c $words[1] gnu=GNU unix -V; then
+
+  (( $+functions[_fuser_services] )) ||
+  _fuser_services() {
+    local expl suf ret=1
+
+    [[ $opt_args[-n] = ??p || $EUID = 0 ]] || return
+
+    if compset -P '*/'; then
+      _wanted protocols expl protocol compadd tcp udp
+    elif compset -P '*,*,'; then
+      compset -S '/*' || [[ -n $opt_args[-n] ]] || suf=( -qS / )
+      _ports $suf && ret=0
+    elif compset -P '*,'; then
+      compset -S ',*' || suf=( -S ,  -r "/ \t\n\-" )
+      _hosts $suf && ret=0
+    else
+      compset -S ',*' || suf=( -S ${${opt_args[-n]/?*/,}:-/} -r "/, \t\n\-" )
+      _ports $suf && ret=0
+    fi
+      
+    return ret
+  }
+
   _arguments \
 	 '(-s)-a[show all files specified on the command line]' \
 	 {-c,-m}'[list all processes accessing files on the filesystem specified by name]' \
@@ -17,7 +41,8 @@
 	 '-V[display version information]' \
 	 '-4[search only for IPv4 sockets]' \
 	 '-6[search only for IPv6 sockets]' \
-	 ':name:_files'
+	 '*:name: _alternative "files:file:_files" "services:service:_fuser_services"'
+
 else
   case $OSTYPE in
     solaris2.9 )


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


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

only message in thread, other threads:[~2005-04-01 19:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-01 19:34 PATCH: complete services in _fuser Oliver Kiddle

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).