summary refs log tree commit diff
path: root/Completion/Builtins
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
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')
-rw-r--r--Completion/Builtins/_pids24
-rw-r--r--Completion/Builtins/_zstyle6
2 files changed, 16 insertions, 14 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
diff --git a/Completion/Builtins/_zstyle b/Completion/Builtins/_zstyle
index abfec06d3..3a485f0da 100644
--- a/Completion/Builtins/_zstyle
+++ b/Completion/Builtins/_zstyle
@@ -103,9 +103,9 @@ displays expansions extensions files fonts functions globbed-files groups
 history-words hosts indexes jobs keymaps keysyms local-directories
 libraries limits manuals maps messages modifiers modules my-accounts
 named-directories names nicknames options original other-accounts packages
-parameters path-directories paths pods ports prefixes processes ps regex
-sequences sessions signals strings tags targets types urls users values
-warnings widgets windows zsh-options)
+parameters path-directories paths pods ports prefixes processes
+processes-names ps regex sequences sessions signals strings tags targets
+types urls users values warnings widgets windows zsh-options)
 
 _arguments -C ':context:->contexts' ':style:->styles' '*:argument:->style-arg'