about summary refs log tree commit diff
path: root/Completion/Builtins/_pids
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-08-15 09:31:18 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-08-15 09:31:18 +0000
commit0352b80797d54dbfdd6f7f27e24980b0d8c0b666 (patch)
tree3db539db7cff1d5a97ee1e75483de6cdde11ad8d /Completion/Builtins/_pids
parenta070f9bb56983c10d87d2d97239a7f559a7dd534 (diff)
downloadzsh-0352b80797d54dbfdd6f7f27e24980b0d8c0b666.tar.gz
zsh-0352b80797d54dbfdd6f7f27e24980b0d8c0b666.tar.xz
zsh-0352b80797d54dbfdd6f7f27e24980b0d8c0b666.zip
call ps only once and be more intelligent when finding the PIDs (12640)
Diffstat (limited to 'Completion/Builtins/_pids')
-rw-r--r--Completion/Builtins/_pids24
1 files changed, 13 insertions, 11 deletions
diff --git a/Completion/Builtins/_pids b/Completion/Builtins/_pids
index 3e1ad4758..b3ff1a058 100644
--- a/Completion/Builtins/_pids
+++ b/Completion/Builtins/_pids
@@ -3,7 +3,7 @@
 # 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 all nm ret=1
+local out pids index list expl match desc listargs args all nm ret=1
 
 _tags processes || return 1
 
@@ -22,24 +22,26 @@ fi
 
 zstyle -s ":completion:${curcontext}:processes" command args
 
-out="$(_call processes ps 2>/dev/null)"
+out=( "${(@f)$(_call processes ps 2>/dev/null)}" )
+desc="$out[1]"
+out=( "${(@M)out[2,-1]:#${~match}}" )
+
+if [[ "$desc" = (#i)(|*[[:blank:]])pid(|[[:blank:]]*) ]]; then
+  index="${#desc[1,(r)(#i)[[:blank:]]pid]}"
+  pids=( "${(@)${(@M)out#${(l:index::?:)~:-}[^[:blank:]]#}##*[[:blank:]]}" )
+else
+  pids=( "${(@)${(@M)out##[^0-9]#[0-9]#}##*[[:blank:]]}" )
+fi
 
 if zstyle -T ":completion:${curcontext}:processes" verbose; then
-  zstyle -s ":completion:${curcontext}:processes-list" command listargs
-  (( $#listargs )) || listargs=( "$args[@]" )
-  if [[ "$listargs" = "$args" ]]; then
-    list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#${~match}}")
-  else
-    list=("${(@Mr:COLUMNS-1:)${(f@)$(_call processes-list ps 2>/dev/null)}[2,-1]:#${~match}}")
-  fi
+  list=( "${(@Mr:COLUMNS-1:)out}" )
   desc=(-ld list)
 else
   desc=()
 fi
 
 _wanted processes expl 'process ID' \
-    compadd "$@" "$desc[@]" "$all[@]" - \
-        ${${${(M)${(f)"${out}"}[2,-1]:#${~match}}## #}%% *} && ret=0
+    compadd "$@" "$desc[@]" "$all[@]" -a pids && ret=0
 
 if [[ -n "$all" ]]; then
   zstyle -s ":completion:${curcontext}:processes" insert-ids out || out=menu