mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-11 13:01:28 +02:00
43192: _pgrep: simplify completions of list of IDs
This commit is contained in:
parent
3ec9503f49
commit
e558f23131
2 changed files with 27 additions and 89 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2018-07-20 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
|
||||||
|
|
||||||
|
* 43192: Completion/Unix/Command/_pgrep: simplify the completions
|
||||||
|
of comma-separated list of IDs.
|
||||||
|
|
||||||
2018-07-19 dana <dana@dana.is>
|
2018-07-19 dana <dana@dana.is>
|
||||||
|
|
||||||
* 43186 (tweaked): Completion/Unix/Command/_crontab: Add completion
|
* 43186 (tweaked): Completion/Unix/Command/_crontab: Add completion
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#compdef pgrep pkill
|
#compdef pgrep pkill
|
||||||
|
|
||||||
# Notes:
|
# Notes:
|
||||||
# - We assume that Linux systems use procps-ng — specifically, procps-ng >=3.3.4
|
# - We assume that Linux systems use procps-ng - specifically, procps-ng >=3.3.4
|
||||||
# (which changed the behaviour of -f and added -a)
|
# (which changed the behaviour of -f and added -a)
|
||||||
# - We don't really need to keep pgopts and pkopts separate, but it seems like
|
# - We don't really need to keep pgopts and pkopts separate, but it seems like
|
||||||
# it should make things a bit easier to follow
|
# it should make things a bit easier to follow
|
||||||
|
@ -26,7 +26,6 @@ arguments=(
|
||||||
'(: * -)'{-h,--help}'[display help information]'
|
'(: * -)'{-h,--help}'[display help information]'
|
||||||
'-I[request confirmation before signalling each process]'
|
'-I[request confirmation before signalling each process]'
|
||||||
'-i[ignore case distinctions]'
|
'-i[ignore case distinctions]'
|
||||||
'-J+[match only on specified project IDs]: :->projid'
|
|
||||||
'-j+[match only on specified jail IDs]:jail:_sequence _jails -0 -o jid'
|
'-j+[match only on specified jail IDs]:jail:_sequence _jails -0 -o jid'
|
||||||
'(-L --logpidfile)'{-L,--logpidfile}'[fail if PID file not locked (with -F)]'
|
'(-L --logpidfile)'{-L,--logpidfile}'[fail if PID file not locked (with -F)]'
|
||||||
'(-N)-M+[extract name list from specified core]:core file:_files'
|
'(-N)-M+[extract name list from specified core]:core file:_files'
|
||||||
|
@ -37,7 +36,7 @@ arguments=(
|
||||||
'(-l)-q[suppress normal output]'
|
'(-l)-q[suppress normal output]'
|
||||||
'-S[search also in system processes (kernel threads)]'
|
'-S[search also in system processes (kernel threads)]'
|
||||||
'(-s --session)'{-s+,--session=}'[match only on specified process session IDs]: :->sid'
|
'(-s --session)'{-s+,--session=}'[match only on specified process session IDs]: :->sid'
|
||||||
# _signals is OK here — we do it differently below
|
# _signals is OK here - we do it differently below
|
||||||
'(ss)--signal=[specify signal to send to process]: :_signals -s'
|
'(ss)--signal=[specify signal to send to process]: :_signals -s'
|
||||||
'-T+[match only on specified routing table]:routing table'
|
'-T+[match only on specified routing table]:routing table'
|
||||||
'(-t --terminal)'{-t+,--terminal=}'[match only on specified controlling terminals]: :_sequence _ttys -do'
|
'(-t --terminal)'{-t+,--terminal=}'[match only on specified controlling terminals]: :_sequence _ttys -do'
|
||||||
|
@ -87,11 +86,12 @@ case $OSTYPE in
|
||||||
pkopts=aFfGgIiLlnoPtUuvx
|
pkopts=aFfGgIiLlnoPtUuvx
|
||||||
;;
|
;;
|
||||||
solaris*)
|
solaris*)
|
||||||
pgopts=cdfGgJlnoPsTtUuvxz
|
pgopts=cdfGglnoPsTtUuvxz
|
||||||
pkopts=cfGgJnoPsTtUuvxz
|
pkopts=cfGgnoPsTtUuvxz
|
||||||
arguments=(
|
arguments=(
|
||||||
${arguments:#((#s)|*\))(\*|)-[cT]*}
|
${arguments:#((#s)|*\))(\*|)-[cT]*}
|
||||||
'-c+[match only on specified contract IDs]: :->contract'
|
'-c+[match only on specified contract IDs]: :->contract'
|
||||||
|
'-J+[match only on specified project IDs]: :->projid'
|
||||||
'-T+[match only on specified task IDs]: :->task'
|
'-T+[match only on specified task IDs]: :->task'
|
||||||
)
|
)
|
||||||
;;
|
;;
|
||||||
|
@ -130,115 +130,48 @@ arguments+=( $sig_arguments + o '*: :->pname' )
|
||||||
[[ $OSTYPE == linux* ]] || aopts+=( -A '*-' )
|
[[ $OSTYPE == linux* ]] || aopts+=( -A '*-' )
|
||||||
_arguments -C -s -S $aopts : $arguments && ret=0
|
_arguments -C -s -S $aopts : $arguments && ret=0
|
||||||
|
|
||||||
|
# complete comma-separated list of various IDs
|
||||||
|
# $1: tag, $2: description, $3: keyword for 'ps -o'
|
||||||
|
_pgrep_sequence () {
|
||||||
|
_sequence _wanted $1 expl "$2" \
|
||||||
|
compadd - ${(un)$(_call_program $1 ps -A -o $3=)}
|
||||||
|
}
|
||||||
|
|
||||||
case $state in
|
case $state in
|
||||||
(sid)
|
(sid)
|
||||||
if [[ $OSTYPE == openbsd* ]]; then
|
if [[ $OSTYPE == openbsd* ]]; then
|
||||||
break
|
_message 'session ID'
|
||||||
fi
|
|
||||||
|
|
||||||
compset -P '*,'
|
|
||||||
|
|
||||||
local -a used sid
|
|
||||||
used=(${(s:,:)IPREFIX})
|
|
||||||
if [[ $OSTYPE == freebsd* ]]; then
|
|
||||||
sid=(${(uon)$(ps -ax -o sid=)})
|
|
||||||
else
|
else
|
||||||
sid=(${(uon)$(ps -A -o sid=)})
|
_pgrep_sequence session-ids 'session ID' sid
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_wanted sid expl 'session ID' compadd -S ',' -q -F used $sid
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(ppid)
|
(ppid)
|
||||||
compset -P '*,'
|
_pgrep_sequence ppids 'parent process ID' ppid
|
||||||
|
|
||||||
local -a used ppid
|
|
||||||
used=(${(s:,:)IPREFIX})
|
|
||||||
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
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(pgid)
|
(pgid)
|
||||||
compset -P '*,'
|
_pgrep_sequence pgids 'process group ID' pgid
|
||||||
|
|
||||||
local -a used pgid
|
|
||||||
used=(${(s:,:)IPREFIX})
|
|
||||||
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)
|
(projid)
|
||||||
compset -P '*,'
|
_pgrep_sequence project-ids 'project ID' project
|
||||||
|
|
||||||
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)
|
(contract)
|
||||||
compset -P '*,'
|
_pgrep_sequence contract-ids 'contract ID' ctid
|
||||||
|
|
||||||
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)
|
(task)
|
||||||
compset -P '*,'
|
_pgrep_sequence task-ids 'task ID' taskid
|
||||||
|
|
||||||
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)
|
(pname)
|
||||||
local ispat="pattern matching "
|
local ispat="pattern matching "
|
||||||
if (( ${+opt_args[-x]} )); then
|
if (( ${+opt_args[-x]} )); then
|
||||||
ispat=""
|
ispat=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local command
|
|
||||||
if (( ${+opt_args[-f]} )); then
|
if (( ${+opt_args[-f]} )); then
|
||||||
if [[ "$OSTYPE" == freebsd* ]] && (( ${+opt_args[-S]} )); then
|
_wanted process-args expl $ispat'process command line' \
|
||||||
command="$(ps -axH -o command=)"
|
compadd ${${(f)"$(_call_program process-args ps -A -o args=)"}% *}
|
||||||
elif [[ "$OSTYPE" == (freebsd|openbsd|darwin)* ]]; then
|
|
||||||
command="$(ps -ax -o command=)"
|
|
||||||
elif [[ "$OSTYPE" == solaris* ]]; then
|
|
||||||
command="$(ps -A -o args=)"
|
|
||||||
else
|
else
|
||||||
command="$(ps -A o cmd=)"
|
_wanted processes-names expl $ispat'process name' _process_names -a -t
|
||||||
fi
|
|
||||||
_wanted pname expl $ispat'process command line' compadd ${(u)${(f)${command}}}
|
|
||||||
else
|
|
||||||
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
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac && ret=0
|
esac && ret=0
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Reference in a new issue