1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-11-20 14:04:03 +01:00
zsh/Completion/Builtins/_pids
2000-04-01 20:43:43 +00:00

35 lines
1018 B
Plaintext

#autoload
# If given the `-m <pattern>' option, this tries to complete only pids
# of processes whose command line match the `<pattern>'.
local out list expl match desc listargs args
_wanted processes || return 1
if [[ "$1" = -m ]]; then
match="${2}*"
shift 2
fi
zstyle -s ":completion:${curcontext}:pids" command args
out="$(_call pids ps 2>/dev/null)"
if zstyle -T ":completion:${curcontext}:processes" verbose; then
zstyle -s ":completion:${curcontext}:pids-list" command listargs
(( $#listargs )) || listargs=( "$args[@]" )
if [[ "$listargs" = "$args" ]]; then
list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]*${~match}}")
else
list=("${(@Mr:COLUMNS-1:)${(f@)$(_call pids-list ps 2>/dev/null)}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]*${~match}}")
fi
desc=(-ld list)
else
desc=()
fi
_all_labels processes expl 'process ID' \
compadd "$@" "$desc[@]" - \
${${${(M)${(f)"${out}"}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]#*${~match}}## #}%% *}