Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: complete services in _fuser



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 
______________________________________________________________________



Messages sorted by: Reverse Date, Date, Thread, Author