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/_pids33
-rw-r--r--Completion/Builtins/_zstyle7
2 files changed, 34 insertions, 6 deletions
diff --git a/Completion/Builtins/_pids b/Completion/Builtins/_pids
index d3cf8a68e..5956ddb29 100644
--- a/Completion/Builtins/_pids
+++ b/Completion/Builtins/_pids
@@ -3,13 +3,21 @@
 # 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
+local out list expl match desc listargs args all nm ret=1
 
 _tags processes || return 1
 
 if [[ "$1" = -m ]]; then
-  match="${2}*"
+  all=()
+  match="[[:blank:]]#${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*[/[:blank:]]${2}*"
   shift 2
+elif [[ "$PREFIX$SUFFIX" = [0-9]# ]]; then
+  all=()
+  match="[[:blank:]]#${PREFIX}[0-9]#${SUFFIX}[[:blank:]]*"
+else
+  all=(-U)
+  match="*[[:blank:]]*[/[:blank:]]$PREFIX*$SUFFIX*"
+  nm="$compstate[nmatches]"
 fi
 
 zstyle -s ":completion:${curcontext}:processes" command args
@@ -20,9 +28,9 @@ 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]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+    list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#${~match}}")
   else
-    list=("${(@Mr:COLUMNS-1:)${(f@)$(_call processes-list ps 2>/dev/null)}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]*${~match}}")
+    list=("${(@Mr:COLUMNS-1:)${(f@)$(_call processes-list ps 2>/dev/null)}[2,-1]:#${~match}}")
   fi
   desc=(-ld list)
 else
@@ -30,5 +38,18 @@ else
 fi
 
 _wanted processes expl 'process ID' \
-    compadd "$@" "$desc[@]" - \
-        ${${${(M)${(f)"${out}"}[2,-1]:#[ 	]#${PREFIX}[0-9]#${SUFFIX}[ 	]#*${~match}}## #}%% *}
+    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
diff --git a/Completion/Builtins/_zstyle b/Completion/Builtins/_zstyle
index b2bd1d5a8..995c8c6f2 100644
--- a/Completion/Builtins/_zstyle
+++ b/Completion/Builtins/_zstyle
@@ -31,12 +31,14 @@ styles=(
   group-name		 c:
   group-order		 c:tag
   groups		 c:_groups
+  guarded-completer      c:completer
   hidden		 c:bool
   hosts			 c:_hosts
   hosts-ports		 c:host-port
   users-hosts-ports	 c:user-host-port
   ignore-parents         c:ignorepar
   ignored-patterns	 c:
+  insert-ids             c:insert-ids
   insert-unambiguous	 c:bool
   last-prompt		 c:bool
   list			 c:listwhen
@@ -245,6 +247,11 @@ while [[ -n $state ]]; do
       _normal
       ;;
 
+    insert-ids)
+      _wanted values expl 'when to insert process IDs' \
+          compadd - menu single longer
+      ;;
+
     _*)
       ${=ostate}
       ;;