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-05-08 10:16:32 +02:00
|
|
|
local out list expl match desc listargs args all nm ret=1
|
2000-04-01 22:43:43 +02:00
|
|
|
|
2000-04-11 09:57:56 +02:00
|
|
|
_tags processes || return 1
|
1999-11-04 16:44:57 +01:00
|
|
|
|
|
|
|
if [[ "$1" = -m ]]; then
|
2000-05-08 10:16:32 +02:00
|
|
|
all=()
|
|
|
|
match="[[:blank:]]#${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*[/[:blank:]]${2}*"
|
1999-11-04 16:44:57 +01:00
|
|
|
shift 2
|
2000-05-08 10:16:32 +02:00
|
|
|
elif [[ "$PREFIX$SUFFIX" = [0-9]# ]]; then
|
|
|
|
all=()
|
|
|
|
match="[[:blank:]]#${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*"
|
|
|
|
else
|
|
|
|
all=(-U)
|
2000-06-20 09:15:38 +02:00
|
|
|
match="*[[:blank:]]*[[/[:blank:]]$PREFIX*$SUFFIX*"
|
2000-05-08 10:16:32 +02:00
|
|
|
nm="$compstate[nmatches]"
|
1999-11-04 16:44:57 +01:00
|
|
|
fi
|
|
|
|
|
2000-04-13 13:05:15 +02:00
|
|
|
zstyle -s ":completion:${curcontext}:processes" command args
|
2000-04-01 22:43:43 +02:00
|
|
|
|
2000-04-13 13:05:15 +02:00
|
|
|
out="$(_call processes ps 2>/dev/null)"
|
1999-11-04 16:44:57 +01:00
|
|
|
|
2000-04-01 22:43:43 +02:00
|
|
|
if zstyle -T ":completion:${curcontext}:processes" verbose; then
|
2000-04-13 13:05:15 +02:00
|
|
|
zstyle -s ":completion:${curcontext}:processes-list" command listargs
|
2000-04-01 22:43:43 +02:00
|
|
|
(( $#listargs )) || listargs=( "$args[@]" )
|
|
|
|
if [[ "$listargs" = "$args" ]]; then
|
2000-05-08 10:16:32 +02:00
|
|
|
list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#${~match}}")
|
2000-04-01 22:43:43 +02:00
|
|
|
else
|
2000-05-08 10:16:32 +02:00
|
|
|
list=("${(@Mr:COLUMNS-1:)${(f@)$(_call processes-list ps 2>/dev/null)}[2,-1]:#${~match}}")
|
2000-04-01 22:43:43 +02:00
|
|
|
fi
|
|
|
|
desc=(-ld list)
|
|
|
|
else
|
|
|
|
desc=()
|
|
|
|
fi
|
1999-11-04 16:44:57 +01:00
|
|
|
|
2000-04-11 09:57:56 +02:00
|
|
|
_wanted processes expl 'process ID' \
|
2000-05-08 10:16:32 +02:00
|
|
|
compadd "$@" "$desc[@]" "$all[@]" - \
|
|
|
|
${${${(M)${(f)"${out}"}[2,-1]:#${~match}}## #}%% *} && 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
|