diff options
Diffstat (limited to 'Completion/Unix/Command/_pgrep')
-rw-r--r-- | Completion/Unix/Command/_pgrep | 173 |
1 files changed, 143 insertions, 30 deletions
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep index e460202a1..3b180ab2d 100644 --- a/Completion/Unix/Command/_pgrep +++ b/Completion/Unix/Command/_pgrep @@ -1,32 +1,71 @@ -#compdef pgrep pkill +#compdef pgrep pkill 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:_groups' - '-s[match only session id]:session id:->sid' +arguments=('-P[parent process id]:parent process id:->ppid' + '-F[match only in process in pidfile]:files:_files' + '-g[match only in process group ids]:group:->pgid' + '-G[match only real group id]:group:_groups' + '-j[match only in processes inside jails]:jail id:->jid' + '-J[match only in project ids]:project id:->projid' + '-M[extract the name list from the specified core]:files:_files' + '-N[extract the name list from the specified system]:files:_files' + '-s[match only session id]:session id:->sid' '-t[match only controlled by terminal]:terminal device:->tty' - '-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]' - '-v[negate matching]' - '-x[match exactly]' - '*:process name:->pname') + '-T[match only in processes specified routing table in rtable]' + '-u[match only effective user id]:user:_users' + '-U[match only real user id]:user:_users' + '(-n)-o[oldest process]' + '(-o)-n[newest process]' + '-a[include process ancestors in the match list]' + '-c[print a count of matching processes]' + '-f[match against full command line]' + '-i[ignore case distinctions]' + '-I[confirmation before attempting to single each process]' + '-L[given pidfile must be locked]' + '-q[do not write anything to standard output]' + '-S[search also in system processes]' + '-v[negate matching]' + '-x[match exactly]' + '-z[match only in zones]:zone:_zones') -if [[ $service == 'pkill' ]] -then +if [[ $service == 'pkill' ]]; then arguments+=('-'${^signals}'[signal]') -elif [[ $service == 'pgrep' ]] -then +elif [[ $service == 'pgrep' ]]; then arguments+=('-d[output delimiter]:delimiter:compadd ${(s\:\:)IFS}' '-l[list name in addition to id]') fi +local optchars +case "$OSTYPE" in + linux*) + optchars="cflvxdnoPgsuUGt" + ;; + freebsd*) + optchars="LSafilnoqvxFGMNPUdgjstu" + ;; + openbsd*) + optchars="flnoqvxdGgPsTtUu" + ;; + darwin*) + optchars="LafilnoqvxFGPUdgtu" + ;; + solaris*) + optchars="flvxdnoPgsuUGJtTcz" + arguments=( ${arguments##-T*} ) + arguments=( ${arguments##-c*} ) + arguments+=( '-T[match only processes in task ids]:taskid:->task' ) + arguments+=( '-c[match only processes in contract ids]:taskid:->contract' ) + ;; + *) + optchars="flvxdnoPgsuUGt" + ;; +esac +arguments=( ${(M)arguments:#(|\*)(|\(*\))-[$optchars]*} + '*:process name:->pname') + _arguments -s -w $arguments && ret=0 case $state in @@ -39,23 +78,45 @@ case $state in ttys=( /dev/tty*(N) /dev/pts/*(N) ) _wanted tty expl 'terminal device' compadd -S ',' -q -F used ${ttys#/dev/} ;; - + (sid) + if [[ $OSTYPE == openbsd* ]]; then + break + fi + compset -P '*,' local -a used sid used=(${(s:,:)IPREFIX}) - sid=(${(uon)$(ps -A o sid=)}) + if [[ $OSTYPE == freebsd* ]]; then + sid=(${(uon)$(ps -ax -o sid=)}) + else + sid=(${(uon)$(ps -A -o sid=)}) + fi _wanted sid expl 'session id' compadd -S ',' -q -F used $sid ;; - + + (jid) + compset -P '*,' + + local -a used jid + used=(${(s:,:)IPREFIX}) + jid=(${(uon)$(ps -ax -o jid=)}) + + _wanted jid expl 'jail id' compadd -S ',' -q -F used $jid + ;; + (ppid) compset -P '*,' local -a used ppid used=(${(s:,:)IPREFIX}) - ppid=(${(uon)$(ps -A o ppid=)}) + if [[ $OSTYPE == (freebsd|openbsd|darwin)* ]]; then + ppid=(${(uon)$(ps -ax -o ppid=)}) + else + ppid=(${(uon)$(ps -A -o ppid=)}) + fi _wanted ppid expl 'parent process id' compadd -S ',' -q -F used $ppid ;; @@ -65,25 +126,77 @@ case $state in local -a used pgid used=(${(s:,:)IPREFIX}) - pgid=(${(uon)$(ps -A o pgid=)}) + if [[ $OSTYPE == (freebsd|openbsd|darwin)* ]]; then + pgid=(${(uon)$(ps -ax -o pgid=)}) + else + pgid=(${(uon)$(ps -A -o pgid=)}) + fi _wanted pgid expl 'process group id' compadd -S ',' -q -F used $pgid ;; - + + (projid) + compset -P '*,' + + local -a used projid + used=(${(s:,:)IPREFIX}) + projid=(${(uon)$(ps -A -o project=)}) + + _wanted projid expl 'project id' compadd -S ',' -q -F used $projid + ;; + + (contract) + compset -P '*,' + + local -a used ctid + used=(${(s:,:)IPREFIX}) + ctid=(${(uon)$(ps -A -o ctid=)}) + + _wanted ctid expl 'contract id' compadd -S ',' -q -F used $ctid + ;; + + (task) + compset -P '*,' + + local -a used taskid + used=(${(s:,:)IPREFIX}) + taskid=(${(uon)$(ps -A -o project=)}) + + _wanted taskid expl 'task id' compadd -S ',' -q -F used $taskid + ;; + (pname) local ispat="pattern matching " - if (( ${+opt_args[-x]} )) - then + if (( ${+opt_args[-x]} )); then ispat="" fi - if (( ${+opt_args[-f]} )) - then - _wanted pname expl $ispat'process command line' compadd ${(u)${(f)"$(ps -A o cmd=)"}} + + local command + if (( ${+opt_args[-f]} )); then + if [[ "$OSTYPE" == freebsd* ]] && (( ${+opt_args[-S]} )); then + command="$(ps -axH -o command=)" + elif [[ "$OSTYPE" == (freebsd|openbsd|darwin)* ]]; then + command="$(ps -ax -o command=)" + elif [[ "$OSTYPE" == solaris* ]]; then + command="$(ps -A -o args=)" + else + command="$(ps -A o cmd=)" + fi + _wanted pname expl $ispat'process command line' compadd ${(u)${(f)${command}}} else - _wanted pname expl $ispat'process name' compadd ${(u)${(f)"$(ps -A co cmd=)"}} + if [[ "$OSTYPE" == freebsd* ]] && (( ${+opt_args[-S]} )); then + command="$(ps -axcH -o command=)" + elif [[ "$OSTYPE" == (freebsd|openbsd|darwin)* ]]; then + command="$(ps -axc -o command=)" + elif [[ "$OSTYPE" == solaris* ]]; then + command="$(ps -A -o comm=)" + else + command="$(ps -A co cmd=)" + fi + _wanted pname expl $ispat'process name' compadd ${(u)${(f)${command}}} fi ;; - + esac && ret=0 return ret |