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

57 lines
1.5 KiB
Plaintext
Raw Normal View History

1999-11-04 16:44:57 +01:00
#autoload
# If given the `-m <pattern>' option, this tries to complete only pids
# of processes whose command line match the `<pattern>'.
2000-08-16 09:16:12 +02:00
local out pids list expl match desc listargs args all nm ret=1
2000-04-01 22:43:43 +02:00
_tags processes || return 1
1999-11-04 16:44:57 +01:00
if [[ "$1" = -m ]]; then
all=()
match="*[[:blank:]]${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*[/[:blank:]]${2}*"
1999-11-04 16:44:57 +01:00
shift 2
elif [[ "$PREFIX$SUFFIX" = ([%-]*|[0-9]#) ]]; then
all=()
match="*[[:blank:]]${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*"
else
all=(-U)
match="*[[:blank:]]*[[/[:blank:]]$PREFIX*$SUFFIX*"
nm="$compstate[nmatches]"
1999-11-04 16:44:57 +01:00
fi
zstyle -s ":completion:${curcontext}:processes" command args
2000-04-01 22:43:43 +02:00
out=( "${(@f)$(_call processes ps 2>/dev/null)}" )
desc="$out[1]"
out=( "${(@M)out[2,-1]:#${~match}}" )
if [[ "$desc" = (#i)(|*[[:blank:]])pid(|[[:blank:]]*) ]]; then
2000-08-16 09:16:12 +02:00
pids=( "${(@)${(@M)out#${(l.${#desc[1,(r)(#i)[[:blank:]]pid]}..?.)~:-}[^[:blank:]]#}##*[[:blank:]]}" )
else
pids=( "${(@)${(@M)out##[^0-9]#[0-9]#}##*[[:blank:]]}" )
fi
1999-11-04 16:44:57 +01:00
2000-04-01 22:43:43 +02:00
if zstyle -T ":completion:${curcontext}:processes" verbose; then
list=( "${(@Mr:COLUMNS-1:)out}" )
2000-04-01 22:43:43 +02:00
desc=(-ld list)
else
desc=()
fi
1999-11-04 16:44:57 +01:00
_wanted processes expl 'process ID' \
compadd "$@" "$desc[@]" "$all[@]" -a pids && ret=0
if [[ -n "$all" ]]; then
zstyle -s ":completion:${curcontext}:processes" insert-ids out || out=menu
case "$out" in
menu) compstate[insert]=menu ;;
single) [[ $compstate[nmatches] -ne nm+1 ]] && compstate[insert]= ;;
*) [[ ${#:-$PREFIX$SUFFIX} -gt ${#compstate[unambiguous]} ]] &&
compstate[insert]=menu ;;
esac
fi
return ret