summaryrefslogtreecommitdiff
path: root/Completion/Unix/Command/_pgrep
diff options
context:
space:
mode:
authorFrank Terbeck <ft@bewatermyfriend.org>2011-06-02 10:50:35 +0200
committerFrank Terbeck <ft@bewatermyfriend.org>2011-06-02 10:50:35 +0200
commit2438a0e95aa448f0aeda468752444306b44fe7d0 (patch)
tree8477e9c6af360f6a89af13e8cb5f2a4f9c1cff2c /Completion/Unix/Command/_pgrep
parentb495ba1e5a3ab1396844490ad8cad17dec23d6c1 (diff)
parent21266db1d9ae433bf1dcb196a4e258c00541b599 (diff)
downloadzsh-2438a0e95aa448f0aeda468752444306b44fe7d0.tar.gz
zsh-2438a0e95aa448f0aeda468752444306b44fe7d0.zip
Merge commit 'zsh-4.3.12' into debian
Diffstat (limited to 'Completion/Unix/Command/_pgrep')
-rw-r--r--Completion/Unix/Command/_pgrep112
1 files changed, 112 insertions, 0 deletions
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
new file mode 100644
index 000000000..f65324a81
--- /dev/null
+++ b/Completion/Unix/Command/_pgrep
@@ -0,0 +1,112 @@
+#compdef pgrep pkill
+
+local context state line
+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'
+ '-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'
+ '(-n)-o[oldest process]'
+ '(-o)-n[newest process]'
+ '-f[match against full command line]'
+ '-v[negate matching]'
+ '-x[match exactly]'
+ '*:process name:->pname')
+
+if [[ $service == 'pkill' ]]
+then
+ arguments+=('-'${^signals}'[signal]')
+elif [[ $service == 'pgrep' ]]
+then
+ arguments+=('-d[output delimiter]:delimiter:compadd ${(s\:\:)IFS}'
+ '-l[list name in addition to id]')
+fi
+
+_arguments -s -w $arguments
+
+case $state in
+ (tty)
+ compset -P '*,'
+
+ local -a used
+ used=(${(s:,:)IPREFIX})
+
+ compadd -S ',' -q -F used /dev/tty*(:t)
+ ;;
+
+ (sid)
+ compset -P '*,'
+
+ local -a used sid
+ used=(${(s:,:)IPREFIX})
+ sid=(${(uon)$(ps -A o sid=)})
+
+ compadd -S ',' -q -F used $sid
+ ;;
+
+ (ppid)
+ compset -P '*,'
+
+ local -a used ppid
+ used=(${(s:,:)IPREFIX})
+ ppid=(${(uon)$(ps -A o ppid=)})
+
+ compadd -S ',' -q -F used $ppid
+ ;;
+
+ (pgid)
+ compset -P '*,'
+
+ local -a used pgid
+ used=(${(s:,:)IPREFIX})
+ pgid=(${(uon)$(ps -A o pgid=)})
+
+ compadd -S ',' -q -F used $pgid
+ ;;
+
+ (pname)
+ if (( ${+opt_args[-x]} )) && (( ${+opt_args[-f]} ))
+ then
+ compadd ${(u)${(f)"$(ps -A o cmd=)"}}
+ else
+ 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
+ ;;
+
+ (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