about summary refs log tree commit diff
path: root/Completion/Builtins
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Builtins')
-rw-r--r--Completion/Builtins/_kill17
-rw-r--r--Completion/Builtins/_pids18
-rw-r--r--Completion/Builtins/_wait12
3 files changed, 28 insertions, 19 deletions
diff --git a/Completion/Builtins/_kill b/Completion/Builtins/_kill
index b4fa5fb88..bb198b7a4 100644
--- a/Completion/Builtins/_kill
+++ b/Completion/Builtins/_kill
@@ -1,24 +1,21 @@
 #compdef kill
 
-local list expl
+local tags list expl
 
 if compset -P 1 -; then
+
+  _tags -i signal || return 1
+
   _description expl signal
   compadd "$expl[@]" $signals[1,-3]
 else
-  local tags ret=1
+  local ret=1
   
   _tags job process
   
   while _tags; do
-    [[ "$tags" = *:job:* ]] && _jobs && ret=0
-    if [[ "$tags" = *:process:* ]]; then
-      list=("${(@M)${(f@)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*}")
-      _description expl 'process ID'
-      compadd "$expl[@]" -ld list - \
-        ${${${(f)"$(ps $=compconfig[ps_args] 2>/dev/null)"}[2,-1]## #}%% *} &&
-          ret=0
-    fi
+    [[ "$tags" = *:job:*     ]] && _jobs && ret=0
+    [[ "$tags" = *:process:* ]] && _pids && ret=0
     (( ret )) || break
   done
 
diff --git a/Completion/Builtins/_pids b/Completion/Builtins/_pids
new file mode 100644
index 000000000..0ffda900b
--- /dev/null
+++ b/Completion/Builtins/_pids
@@ -0,0 +1,18 @@
+#autoload
+
+# If given the `-m <pattern>' option, this tries to complete only pids
+# of processes whose command line match the `<pattern>'.
+
+local list expl match
+
+if [[ "$1" = -m ]]; then
+  match="${2}*"
+  shift 2
+fi
+
+_description expl 'process ID'
+
+list=("${(@Mr:COLUMNS-1:)${(f@)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+
+compadd "$expl[@]" "$@" -ld list - \
+  ${${${(M)${(f)"$(ps $=compconfig[ps_args] 2>/dev/null)"}[2,-1]:#*${~match}}## #}%% *}
diff --git a/Completion/Builtins/_wait b/Completion/Builtins/_wait
index 0b58367f1..b03aac6e0 100644
--- a/Completion/Builtins/_wait
+++ b/Completion/Builtins/_wait
@@ -1,18 +1,12 @@
 #compdef wait
 
-local tags list ret=1 expl
+local tags ret=1
   
 _tags job process
   
 while _tags; do
-  [[ "$tags" = *:job:* ]] && _jobs && ret=0
-  if [[ "$tags" = *:process:* ]]; then
-    list=("${(@M)${(f@)$(ps ${=compconfig[ps_listargs]:-$=compconfig[ps_args]} 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*}")
-    _description expl 'process ID'
-    compadd "$expl[@]" -ld list - \
-      ${${${(f)"$(ps $=compconfig[ps_args] 2>/dev/null)"}[2,-1]## #}%% *} &&
-        ret=0
-  fi
+  [[ "$tags" = *:job:*     ]] && _jobs && ret=0
+  [[ "$tags" = *:process:* ]] && _pids && ret=0
   (( ret )) || break
 done