Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Suggestion for _killall



Falk Hueffner wrote:

> Hi,
> 
> I suggest this patch for _killall to also complete command names:

I suggest that we use the patch below instead -- it uses descriptions
and tags. This also (finally) adds the function `_signals' to complete 
signal names and makes it be used everywhere. This also uses/tests the 
prefix-needed and prefix-hidden styles.

Bye
 Sven

diff -u -r oldcompletion/Builtins/_kill Completion/Builtins/_kill
--- oldcompletion/Builtins/_kill	Thu Nov 18 08:51:26 1999
+++ Completion/Builtins/_kill	Fri Nov 19 09:48:58 1999
@@ -1,10 +1,6 @@
 #compdef kill
 
-local list expl
-
-if compset -P 1 -; then
-  _wanted -C - expl signal &&
-      compadd "$expl[@]" $signals[1,-3]
-else
-  _alternative -C argument 'jobs:: _jobs' 'processes:: _pids'
-fi
+_alternative \
+    'signals:: _signals -p' \
+    'jobs:: _jobs' \
+    'processes:: _pids'
diff -u -r oldcompletion/Builtins/_signals Completion/Builtins/_signals
--- oldcompletion/Builtins/_signals	Fri Nov 19 09:50:30 1999
+++ Completion/Builtins/_signals	Fri Nov 19 09:53:49 1999
@@ -0,0 +1,36 @@
+#autoload
+
+# Options (only in separate words):
+#
+# -a  use all signals (even the pseudo-signals)
+# -p  needs a `-' prefix
+#
+# A `-' or `--' as the first argument is ignored.
+
+local expl last=-3 minus
+
+while [[ "$1" = -[ap] ]]; do
+  if [[ "$1" = -a ]]; then
+    last=-1
+  else
+    minus=-
+  fi
+  shift
+done
+
+[[ "$1" = -(|-) ]] && shift
+
+if _wanted signals expl signal &&
+       { [[ -z "$minus" ]] || ! _style signals prefix-needed ||
+         [[ "$PREFIX" = -* ]] } ; then
+  local disp tmp
+
+  if _style signals prefix-hidden; then
+    tmp=( "${(@)signals[1,last]}" )
+    disp=(-d tmp)
+  else
+    disp=()
+  fi
+  compadd "$@" "$expl[@]" "$disp[@]" -M 'm:{a-z}=${A-Z}' - \
+          "${minus}${(@)^signals[1,last]}"
+fi
diff -u -r oldcompletion/Builtins/_trap Completion/Builtins/_trap
--- oldcompletion/Builtins/_trap	Thu Nov 18 08:51:27 1999
+++ Completion/Builtins/_trap	Fri Nov 19 09:50:16 1999
@@ -6,5 +6,5 @@
   compset -q
   _normal
 else
-  _wanted signals expl signal && compadd "$expl[@]" - "$signals[@]"
+  _signals -a
 fi
diff -u -r oldcompletion/User/_killall Completion/User/_killall
--- oldcompletion/User/_killall	Thu Nov 18 08:51:35 1999
+++ Completion/User/_killall	Fri Nov 19 09:47:57 1999
@@ -1,4 +1,5 @@
 #compdef killall
 
-compset -P 1 - && _wanted -C - signals expl signal &&
-    compadd "$expl[@]" $signals[1,-3]
+_alternative \
+    'signals:: _signals -p' \
+    'processes:process:{ compadd "$expl[@]" ${$(ps ho comm 2> /dev/null):#(ps|COMMAND)} }'

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author