mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-05-20 06:56:05 +02:00
43079, 43086: new utility to complete names of running processes
And new completions for dtruss, fs_usage and sc_usage.
This commit is contained in:
parent
951b945279
commit
a0233a74e3
|
@ -1,3 +1,10 @@
|
|||
2018-06-25 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
|
||||
|
||||
* 43079, 43086: Completion/Unix/Type/_process_names,
|
||||
Completion/Unix/Command/_dtruss, Completion/Darwin/Command/_fs_usage,
|
||||
Completion/Darwin/Command/_sc_usage: new utility to complete names
|
||||
of running processes, and three new completion functions which use it.
|
||||
|
||||
2018-06-24 dana <dana@dana.is>
|
||||
|
||||
* unposted: Completion/Linux/Command/_opkg: Fix mistyped variable
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#compdef fs_usage
|
||||
|
||||
local curcontext="$curcontext" state state_descr line ret=1
|
||||
typeset -A opt_args
|
||||
|
||||
_arguments -s -C -A '-*' : \
|
||||
'-e[exclude fs_usage and the specified processes from sampling]' \
|
||||
'-w[use wider output]' \
|
||||
'*-f+[specify output filtering mode]:mode:(nework filesys pathname exec diskio cachehit)' \
|
||||
'-b[annotate disk I/O events with BootCache info]' \
|
||||
'(-R -S -E)-t+[specify run timeout]:seconds' \
|
||||
'(-t)-R+[specify raw trace file to process]:raw trace file:_files' \
|
||||
'(-t)-S+[specify time to begin processing the trace file]:seconds' \
|
||||
'(-t)-E+[specify time to stop processing the trace file]:seconds' \
|
||||
'*: :->pid-or-pname' && ret=0
|
||||
|
||||
case $state in
|
||||
(pid-or-pname)
|
||||
if [[ -z $opt_args[-R] ]]; then
|
||||
_alternative "processes:: _pids" \
|
||||
"processes-names:: _process_names -a" && ret=0
|
||||
else
|
||||
_message 'pid or process name in the trace file' && ret=0
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
return ret
|
|
@ -0,0 +1,10 @@
|
|||
#compdef sc_usage
|
||||
|
||||
_arguments -s -A '-*' : \
|
||||
'-c+[specify code file to use]:code file:_files' \
|
||||
'-e[sort output by call count]' \
|
||||
'-l[use scrolling output style instead of window updating style]' \
|
||||
'-s+[specify sampling interval]:seconds' \
|
||||
'(- :)-E[specify command path and args to excute]: :_absolute_command_paths:*:: :_normal' \
|
||||
'1: : _alternative "processes:: _pids"
|
||||
"processes-names:: _process_names -a"'
|
|
@ -0,0 +1,18 @@
|
|||
#compdef dtruss
|
||||
|
||||
_arguments -s : \
|
||||
'-a[print all details]' \
|
||||
'-b+[specify dynamic variable buffer size]:buffer size (default 4m)' \
|
||||
'-c[print system call counts]' \
|
||||
'-d[print relative timestamps]' \
|
||||
'-e[print elapsed times]' \
|
||||
'-f[follow children as they are forked]' \
|
||||
'-l[force printing of pid/lwpid per line]' \
|
||||
"-L[don't print pid/lwpid per line]" \
|
||||
'(-p :)-n+[examine processes with the specified name]: : _process_names -a' \
|
||||
'-o[print on-cpu times]' \
|
||||
'-s[print stack backtraces]' \
|
||||
'(-n :)-p+[examine process with the specified pid]: : _pids' \
|
||||
'-t+[examine only the specified syscall]: : _sys_calls' \
|
||||
'1: : _command_names -e' \
|
||||
'*:: : _normal'
|
|
@ -0,0 +1,44 @@
|
|||
#autoload
|
||||
#
|
||||
# complete names of running processes
|
||||
#
|
||||
# options:
|
||||
# -a: include all processes (owned by others, no tty, etc.)
|
||||
# -t: use truncated process names (e.g., those in /proc/PID/stat)
|
||||
# (only on Linux and BSDs)
|
||||
#
|
||||
# this name has been used in _killall and documented in zshcompsys(1)
|
||||
local tagname='processes-names'
|
||||
typeset -a expl opts names all truncate
|
||||
|
||||
zparseopts -E -D 'a=all' 't=truncate'
|
||||
(( $#all )) && opts=( -A )
|
||||
|
||||
local hyphen='-'
|
||||
# on Linux, use BSD-style option to include processes on other ttys
|
||||
[[ $OSTYPE == linux* ]] && hyphen=''
|
||||
|
||||
case $OSTYPE in
|
||||
(linux*|freebsd*|openbsd*|netbsd*)
|
||||
if (( $#truncate )); then
|
||||
if [[ $OSTYPE == netbsd* ]]; then
|
||||
opts+=(-co args=)
|
||||
else
|
||||
opts+=(${hyphen}o comm=)
|
||||
fi
|
||||
names=( ${${(f)"$(_call_program $tagname ps $opts 2>/dev/null)"}#-} )
|
||||
else
|
||||
opts+=(${hyphen}o args=)
|
||||
names=( ${(f)"$(_call_program $tagname ps $opts 2>/dev/null )"} )
|
||||
names=( ${${${${${names:#\[*]}%% *}%:}#-}:t}
|
||||
${${${(M)names:#\[*]}#\[}%]} )
|
||||
fi
|
||||
;;
|
||||
(*)
|
||||
# ignore -t option
|
||||
opts+=(-o comm=)
|
||||
names=( ${${${(f)"$(_call_program $tagname ps $opts 2>/dev/null)"}#-}:t} )
|
||||
;;
|
||||
esac
|
||||
|
||||
_wanted $tagname expl 'process name' compadd "$@" -F '(ps)' -a - names
|
Loading…
Reference in New Issue