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

PATCH: fix _pgrep



avoid reimplementing _users and _groups, use _wanted so we get
descriptions, return 0 on success, fix checks on -f and -x.

---
 Completion/Unix/Command/_pgrep |   62 ++++++++++++---------------------------
 1 files changed, 19 insertions(+), 43 deletions(-)

diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index f65324a..5757c6e 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -1,16 +1,16 @@
 #compdef pgrep pkill 
 
-local context state line
+local context state line ret=1 expl
 typeset -A opt_args
 typeset -a arguments
 
 arguments=('-P[parent process id]:parent process id:->ppid' 
 	   '-g[match only in process group ids]:group:->pgid' 
-	   '-G[match only real group id]:group:->group' 
+	   '-G[match only real group id]:group:_groups' 
 	   '-s[match only session id]:session id:->sid' 
 	   '-t[match only controlled by terminal]:terminal device:->tty'
-	   '-u[match only effective user id]:user:->user' 
-	   '-U[match only real user id]:user:->user' 
+	   '-u[match only effective user id]:user:_users' 
+	   '-U[match only real user id]:user:_users' 
            '(-n)-o[oldest process]' 
 	   '(-o)-n[newest process]' 
 	   '-f[match against full command line]' 
@@ -27,7 +27,7 @@ then
 		    '-l[list name in addition to id]')
 fi
 
-_arguments -s -w $arguments
+_arguments -s -w $arguments && ret=0
 
 case $state in
 	(tty)
@@ -36,7 +36,7 @@ case $state in
 		local -a used
 		used=(${(s:,:)IPREFIX})
 
-		compadd -S ',' -q -F used /dev/tty*(:t)
+		_wanted tty expl 'terminal device' compadd -S ',' -q -F used /dev/tty*(:t)
 		;;
 		
 	(sid)
@@ -46,7 +46,7 @@ case $state in
 		used=(${(s:,:)IPREFIX})
 		sid=(${(uon)$(ps -A o sid=)})
 
-		compadd -S ',' -q -F used $sid
+		_wanted sid expl 'session id' compadd -S ',' -q -F used $sid
 		;;
 	
 	(ppid)
@@ -56,7 +56,7 @@ case $state in
 		used=(${(s:,:)IPREFIX})
 		ppid=(${(uon)$(ps -A o ppid=)})
 
-		compadd -S ',' -q -F used $ppid
+		_wanted ppid expl 'parent process id' compadd -S ',' -q -F used $ppid
 		;;
 
 	(pgid)
@@ -66,47 +66,23 @@ case $state in
 		used=(${(s:,:)IPREFIX})
 		pgid=(${(uon)$(ps -A o pgid=)})
 
-		compadd -S ',' -q -F used $pgid
+		_wanted pgid expl 'process group id' compadd -S ',' -q -F used $pgid
 		;;
 	
 	(pname)
-		if (( ${+opt_args[-x]} )) && (( ${+opt_args[-f]} ))
+    local ispat="pattern matching "
+    if (( ${+opt_args[-x]} ))
+    then
+      ispat=""
+    fi
+		if (( ${+opt_args[-f]} ))
 		then
-			compadd ${(u)${(f)"$(ps -A o cmd=)"}}
+			_wanted pname expl $ispat'process command line' compadd ${(u)${(f)"$(ps -A o cmd=)"}}
 		else
-			compadd ${(u)${(f)"$(ps -A co cmd=)"}}
+			_wanted pname expl $ispat'process name' compadd ${(u)${(f)"$(ps -A co cmd=)"}}
 		fi
 		;;
 	
-	(group)
-		compset -P '*,'
-
-		local group
-		group=$(getent group)
-
-		local -a groups ids
-		groups=(${${(f)group}%%:*})
-		ids=(${${${(f)group}#*:*:}%%:*})
-
-		local -a used
-		used=(${(s:,:)IPREFIX})
-
-		compadd -S ',' -q -F used -d ids $groups $groups
-		;;
+esac && ret=0
 
-	(user)
-		compset -P '*,'
-
-		local passwd
-		passwd=$(getent passwd)
-
-		local -a users ids
-		users=(${${(f)passwd}%%:*})
-		ids=(${${${(f)passwd}#*:*:}%%:*})
-		
-		local -a used
-		used=(${(s:,:)IPREFIX})
-
-		compadd -S ',' -q -F used -d ids $users $users
-		;;
-esac
+return ret
-- 
1.7.5.4



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