* [PATCH 0/3] _pgrep: fixes and improvements
@ 2014-03-11 17:04 Kosuke Asami
2014-03-11 17:04 ` [PATCH 1/3] _pgrep: add missing options in each environments Kosuke Asami
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kosuke Asami @ 2014-03-11 17:04 UTC (permalink / raw)
To: zsh-workers; +Cc: Kosuke Asami
pgrep completion uses 'ps' commands, but in BSD environment, it has
wrong 'ps' options, so it doesn't work showing error messages like a
following line.
ps: illegal argument: co
These patches fix this problem.
And, pgrep options are different between operating systems.
They also deal with it.
Kosuke Asami (3):
_pgrep: add missing options in each environments
_pgrep: fix commands used in completion
_pgrep: tidying up
Completion/Unix/Command/_pgrep | 130 +++++++++++++++++++++++++++++++----------
1 file changed, 100 insertions(+), 30 deletions(-)
--
1.9.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] _pgrep: add missing options in each environments
2014-03-11 17:04 [PATCH 0/3] _pgrep: fixes and improvements Kosuke Asami
@ 2014-03-11 17:04 ` Kosuke Asami
2014-03-11 17:04 ` [PATCH 2/3] _pgrep: fix commands used in completion Kosuke Asami
2014-03-11 17:04 ` [PATCH 3/3] _pgrep: tidying up Kosuke Asami
2 siblings, 0 replies; 4+ messages in thread
From: Kosuke Asami @ 2014-03-11 17:04 UTC (permalink / raw)
To: zsh-workers; +Cc: Kosuke Asami
pgrep options are different between operating systems.
---
Completion/Unix/Command/_pgrep | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index e460202..e4bd2e2 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -5,18 +5,29 @@ typeset -A opt_args
typeset -a arguments
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]'
+ '-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'
+ '-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]'
- '*:process name:->pname')
+ '-x[match exactly]')
if [[ $service == 'pkill' ]]
then
@@ -27,6 +38,27 @@ then
'-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"
+ ;;
+ *)
+ optchars="flvxdnoPgsuUGt"
+ ;;
+esac
+arguments=( ${(M)arguments:#(|\*)(|\(*\))-[$optchars]*}
+ '*:process name:->pname')
+
_arguments -s -w $arguments && ret=0
case $state in
--
1.9.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] _pgrep: fix commands used in completion
2014-03-11 17:04 [PATCH 0/3] _pgrep: fixes and improvements Kosuke Asami
2014-03-11 17:04 ` [PATCH 1/3] _pgrep: add missing options in each environments Kosuke Asami
@ 2014-03-11 17:04 ` Kosuke Asami
2014-03-11 17:04 ` [PATCH 3/3] _pgrep: tidying up Kosuke Asami
2 siblings, 0 replies; 4+ messages in thread
From: Kosuke Asami @ 2014-03-11 17:04 UTC (permalink / raw)
To: zsh-workers; +Cc: Kosuke Asami
The option style in ps command are different between BSD and Linux.
For example, 'ps -A co cmd=' command cannot be executed in BSD
environment, so zsh completion always shows error like 'ps: illegal
argument: co' and cannot be used.
---
Completion/Unix/Command/_pgrep | 54 +++++++++++++++++++++++++++++++++++++-----
1 file changed, 48 insertions(+), 6 deletions(-)
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index e4bd2e2..15b1f44 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -8,7 +8,7 @@ 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]'
+ '-j[match only in processes inside jails]:jail id:->jid'
'-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'
@@ -73,21 +73,43 @@ case $state in
;;
(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
;;
@@ -97,7 +119,11 @@ 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
;;
@@ -108,11 +134,27 @@ case $state in
then
ispat=""
fi
+
+ local command
if (( ${+opt_args[-f]} ))
then
- _wanted pname expl $ispat'process command line' compadd ${(u)${(f)"$(ps -A o cmd=)"}}
+ if [[ "$OSTYPE" == freebsd* ]] && (( ${+opt_args[-S]} )); then
+ command="$(ps -axH -o command=)"
+ elif [[ "$OSTYPE" == (freebsd|openbsd|darwin)* ]]; then
+ command="$(ps -ax -o command=)"
+ 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=)"
+ else
+ command="$(ps -A co cmd=)"
+ fi
+ _wanted pname expl $ispat'process name' compadd ${(u)${(f)${command}}}
fi
;;
--
1.9.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] _pgrep: tidying up
2014-03-11 17:04 [PATCH 0/3] _pgrep: fixes and improvements Kosuke Asami
2014-03-11 17:04 ` [PATCH 1/3] _pgrep: add missing options in each environments Kosuke Asami
2014-03-11 17:04 ` [PATCH 2/3] _pgrep: fix commands used in completion Kosuke Asami
@ 2014-03-11 17:04 ` Kosuke Asami
2 siblings, 0 replies; 4+ messages in thread
From: Kosuke Asami @ 2014-03-11 17:04 UTC (permalink / raw)
To: zsh-workers; +Cc: Kosuke Asami
---
Completion/Unix/Command/_pgrep | 42 +++++++++++++++++++-----------------------
1 file changed, 19 insertions(+), 23 deletions(-)
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index 15b1f44..f06d26e 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -1,39 +1,37 @@
-#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'
+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'
+ '-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'
'-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'
+ '-s[match only session id]:session id:->sid'
'-t[match only controlled by terminal]:terminal device:->tty'
'-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]'
+ '-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]'
+ '-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]'
+ '-v[negate matching]'
'-x[match exactly]')
-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
@@ -71,7 +69,7 @@ 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
@@ -89,7 +87,7 @@ case $state in
_wanted sid expl 'session id' compadd -S ',' -q -F used $sid
;;
-
+
(jid)
compset -P '*,'
@@ -127,17 +125,15 @@ case $state in
_wanted pgid expl 'process group id' compadd -S ',' -q -F used $pgid
;;
-
+
(pname)
local ispat="pattern matching "
- if (( ${+opt_args[-x]} ))
- then
+ if (( ${+opt_args[-x]} )); then
ispat=""
fi
local command
- if (( ${+opt_args[-f]} ))
- then
+ if (( ${+opt_args[-f]} )); then
if [[ "$OSTYPE" == freebsd* ]] && (( ${+opt_args[-S]} )); then
command="$(ps -axH -o command=)"
elif [[ "$OSTYPE" == (freebsd|openbsd|darwin)* ]]; then
@@ -157,7 +153,7 @@ case $state in
_wanted pname expl $ispat'process name' compadd ${(u)${(f)${command}}}
fi
;;
-
+
esac && ret=0
return ret
--
1.9.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-03-11 17:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-11 17:04 [PATCH 0/3] _pgrep: fixes and improvements Kosuke Asami
2014-03-11 17:04 ` [PATCH 1/3] _pgrep: add missing options in each environments Kosuke Asami
2014-03-11 17:04 ` [PATCH 2/3] _pgrep: fix commands used in completion Kosuke Asami
2014-03-11 17:04 ` [PATCH 3/3] _pgrep: tidying up Kosuke Asami
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).