1 #compdef pflags pcred pmap pldd psig pstack pfiles pwdx pstop prun pwait ptree
3 # If given the `-m <pattern>' option, this tries to complete only pids
4 # of processes whose command line match the `<pattern>'.
6 local out pids list expl match desc listargs all nm ret=1
8 _tags processes || return 1
10 if [[ "$1" = -m ]]; then
12 match="*[[:blank:]]${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*[/[:blank:]]${2}*"
14 elif [[ "$PREFIX$SUFFIX" = ([%-]*|[0-9]#) ]]; then
16 match="(*[[:blank:]]|)${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*"
19 match="*[[:blank:]]*[[/[:blank:]]$PREFIX*$SUFFIX*"
20 nm="$compstate[nmatches]"
23 out=( "${(@f)$(_call_program processes ps 2>/dev/null)}" )
25 out=( "${(@M)out[2,-1]:#${~match}}" )
27 if [[ "$desc" = (#i)(|*[[:blank:]])pid(|[[:blank:]]*) ]]; then
28 pids=( "${(@)${(@M)out#${(l.${#desc[1,(r)(#i)[[:blank:]]pid]}..?.)~:-}[^[:blank:]]#}##*[[:blank:]]}" )
30 pids=( "${(@)${(@M)out##[^0-9]#[0-9]#}##*[[:blank:]]}" )
33 if zstyle -T ":completion:${curcontext}:processes" verbose; then
34 list=( "${(@Mr:COLUMNS-1:)out}" )
40 _wanted processes expl 'process ID' \
41 compadd "$@" "$desc[@]" "$all[@]" -a - pids && ret=0
43 if [[ -n "$all" ]]; then
44 zstyle -s ":completion:${curcontext}:processes" insert-ids out || out=menu
47 menu) compstate[insert]=menu ;;
48 single) [[ $compstate[nmatches] -ne nm+1 && $compstate[insert] != menu ]] &&
50 *) [[ ${#:-$PREFIX$SUFFIX} -gt ${#compstate[unambiguous]} ]] &&
51 compstate[insert]=menu ;;