about summary refs log tree commit diff
path: root/Completion/Builtins/_pids
blob: d74cd9a5681b92be269f247cd47fbf027797410d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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 expl 'process ID' || return 1

if [[ "$1" = -m ]]; then
  match="${2}*"
  shift 2
fi

zstyle -a ":completion:${curcontext}:ps" arguments args

out="$(command ps $args 2>/dev/null)"

if zstyle -T ":completion:${curcontext}:processes" verbose; then
  zstyle -a ":completion:${curcontext}:ps" list-arguments 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@)$(command ps $listargs 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
  fi
  desc=(-ld list)
else
  desc=()
fi

compadd "$expl[@]" "$@" "$desc[@]" - \
    ${${${(M)${(f)"$(command ps $args 2>/dev/null)"}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]#*${~match}}## #}%% *}