zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] rewrite _killall
@ 2018-06-28  7:39 Jun T
  2018-06-28 13:10 ` Jun T.
  2018-06-28 14:52 ` dana
  0 siblings, 2 replies; 6+ messages in thread
From: Jun T @ 2018-06-28  7:39 UTC (permalink / raw)
  To: zsh-workers

_killall has many options which need be completed.
The previous patch to _ttys is required.


diff --git a/Completion/Unix/Command/_killall b/Completion/Unix/Command/_killall
index 375b1bf74..989772c5d 100644
--- a/Completion/Unix/Command/_killall
+++ b/Completion/Unix/Command/_killall
@@ -1,9 +1,77 @@
 #compdef killall killall5
 
-if [[ $service = killall && "$OSTYPE" = (linux*|*bsd*|darwin*) ]]; then
-  _alternative \
-    'signals:: _signals -p' \
-    'processes-names:process:{ compadd "$expl[@]" ${${${${(f)"$(_call_program processes-names ps ${${EUID/(#s)0(#e)/xa}//[0-9]#/}ho command 2> /dev/null)"//[][\(\)]/}:#(ps|COMMAND|-*)}%%\ *}:t} }'
-else
+if [[ $service = killall5 || $OSTYPE != (linux|*bsd|dragonfly|darwin)* ]]; then
   _signals -p
+  return
+fi
+
+typeset -a opts args
+[[ $EUID = 0 || $_comp_priv_prefix[1] = sudo ]] && opts=( -a )
+
+if _pick_variant psmisc=PSmisc unix --version; then
+
+  local curcontext=$curcontext state state_descr line ret=1
+  typeset -A opt_args
+  args=(
+    '(-e --exact)'{-e,--exact}'[require exact match for names longer than 15 chars]'
+    '(-I --ignore-case)'{-I,--ignore-case}'[do case insensitive process name match]'
+    '(-g --process-group)'{-g,--process-group}'[kill the process group to which the process blongs]'
+    '(-i --interactive)'{-i,--interactive}'[interactively ask for confirmation before killing]'
+    '(- : *)'{-l,--list}'[list all known signal names]'
+    '(-n --ns)'{-n,--ns}'[match against the PID namespace of the given PID]:pid: _pids'
+    '(-o --older-than)'{-o,--older-than}'[match only processes older than the specified time]:time:->time'
+    '(-q --quiet)'{-q,--quiet}'[do not complain if no processes were killed]'
+    '(-r --regexp)'{-r,--regexp}'[interpret process name as extended regular expression]'
+    '(-s --signal)'{-s,--signal}'[send the speified signal]:signal:_signals'
+    '(-u --user)'{-u,--user}'[kill only processes owned by specified user]: : _users'
+    '(-v --verbose)'{-v,--verbose}'[report if the signal was successfully sent]'
+    '(-w --wait)'{-w,--wait}'[wait for all killed processes to die]'
+    '(- : *)'{-V,--version}'[display version information]'
+    '(-y --younger-than)'{-y,--younger-than}'[match only processes younger than the specified time]:time:->time'
+    "1: : _alternative 'signals: :_signals -p' 'processes-names: :_process_names $opts'"
+    "*: :_process_names $opts"
+  )
+  [[ $CURRENT = 2 || ( $CURRENT = 3 && $words[2] = (-Z|--context) ) ]] && \
+    args+=( '(-Z --context)'{-Z,--context}'[specify SELinux security context]:regex pattern: ' )
+
+  _arguments -s -S -C : $args && ret=0
+
+  case $state in
+    (time)
+      local -a units=( 's:seconds' 'm:minuts' 'h:hours' 'd:days'
+			'w:weeks' 'M:months' 'y:years' )
+      if compset -P '[0-9]##(|.[0-9]#)'; then
+	_alternative 'float-number:: _message "float number"' \
+		    'unit:: _describe unit units' && ret=0
+      else
+	_message 'float number and unit' && ret=0
+      fi
+      ;;
+  esac
+
+  return ret
+
+else # bsd and darwin
+
+  if [[ $OSTYPE == (freebsd|dragonfly)* ]]; then
+    args=( '-j[kill processes in specified jail]: :_jails -0' )
+    opts+=( -t )  # long process names must be truncated
+  fi
+  args+=(
+    '-v[be more verbose about what will be done]'
+    '-e[use effective user ID for -u option]'
+    '(- : *)-help[give a help on command usage and exit]'
+    '(- : *)-l[list names of available signals and exit]'
+    '-m[interprit specified name as a regular expression]'
+    '-s[show only what will be done, but do notsend any signal]'
+    '-d[print info about processes matched, but do not send any signal]'
+    '-u[limit to processes belonging to specified user]: :_users'
+    '-t[limit to processes running on specified tty]: :_ttys -od'
+    "-c[with -u or -t, limit to processes matching specified name]: :_process_names $opts"
+    '-z[do not skip zombies]'
+    "1: : _alternative 'signals::_signals -p' 'processes-names::_process_names $opts'"
+    "*: :_process_names $opts"
+  )
+  _arguments -s -S : $args
+
 fi




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rewrite _killall
  2018-06-28  7:39 [PATCH] rewrite _killall Jun T
@ 2018-06-28 13:10 ` Jun T.
  2018-06-28 14:52 ` dana
  1 sibling, 0 replies; 6+ messages in thread
From: Jun T. @ 2018-06-28 13:10 UTC (permalink / raw)
  To: zsh-workers


> 2018/06/28 16:39、Jun T <takimoto-j@kba.biglobe.ne.jp>のメール:
> 
> +    '(-s --signal)'{-s,--signal}'[send the speified signal]:signal:_signals'

This line must be

    '(1 -s --signal)'{-s,--signal}'[send the speified signal]:signal:_signals'


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rewrite _killall
  2018-06-28  7:39 [PATCH] rewrite _killall Jun T
  2018-06-28 13:10 ` Jun T.
@ 2018-06-28 14:52 ` dana
  2018-06-29 11:45   ` Jun T
  2018-07-01 16:17   ` Jun T.
  1 sibling, 2 replies; 6+ messages in thread
From: dana @ 2018-06-28 14:52 UTC (permalink / raw)
  To: Jun T; +Cc: zsh-workers

On 28 Jun 2018, at 02:39, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>+if _pick_variant psmisc=PSmisc unix --version; then

Is this OK? I know it's checking for killall5/Solaris early on, but is there any
possibility that a SysV-style killall could slip past that check? Maybe that's
overly paranoid, idk.

On 28 Jun 2018, at 02:39, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>+    '(-n --ns)'{-n,--ns}'[match against the PID namespace of the given PID]:pid: _pids'

Trivial thing, but it seems preferable to let _pids, _signals, &c., handle their
descriptions unless there's a specific need to override them, yeah?

On 28 Jun 2018, at 02:39, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>+    '(-g --process-group)'{-g,--process-group}'[kill the process group to which the process blongs]'
>+    '(-s --signal)'{-s,--signal}'[send the speified signal]:signal:_signals'
>+    '-m[interprit specified name as a regular expression]'
>+    '-s[show only what will be done, but do notsend any signal]'

Some typos here:

* blongs -> belongs
* speified -> specified
* interprit -> interpret
* notsend -> not send

On 28 Jun 2018, at 02:39, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>'(-u --user)'{-u,--user}'[kill only processes owned by specified user]: : _users'
>+    '-u[limit to processes belonging to specified user]: :_users'

These should all be in -o+ and --opt= form, i'd think.

On 28 Jun 2018, at 02:39, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>+  _arguments -s -S : $args

`-A '-*'` would be appropriate for this one.

dana


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rewrite _killall
  2018-06-28 14:52 ` dana
@ 2018-06-29 11:45   ` Jun T
  2018-07-01 16:17   ` Jun T.
  1 sibling, 0 replies; 6+ messages in thread
From: Jun T @ 2018-06-29 11:45 UTC (permalink / raw)
  To: zsh-workers

Thank you for the comments.

> 2018/06/28 23:52、dana <dana@dana.is>のメール:
> 
> On 28 Jun 2018, at 02:39, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>> +if _pick_variant psmisc=PSmisc unix --version; then
> 
> Is this OK? I know it's checking for killall5/Solaris early on, but is there any
> possibility that a SysV-style killall could slip past that check? Maybe that's
> overly paranoid, idk.

I guess on virtually all Linux distros killall comes from psmisc, and if it is
ever not psmics, I think the chances are very low that it is a SysV-variant.

> On 28 Jun 2018, at 02:39, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>> +    '(-n --ns)'{-n,--ns}'[match against the PID namespace of the given PID]:pid: _pids'
> 
> Trivial thing, but it seems preferable to let _pids, _signals, &c., handle their
> descriptions unless there's a specific need to override them, yeah?

The :pid: was doing nothing due to the space before _pids.
I will remove it.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rewrite _killall
  2018-06-28 14:52 ` dana
  2018-06-29 11:45   ` Jun T
@ 2018-07-01 16:17   ` Jun T.
  2018-07-01 19:14     ` dana
  1 sibling, 1 reply; 6+ messages in thread
From: Jun T. @ 2018-07-01 16:17 UTC (permalink / raw)
  To: zsh-workers


> 2018/06/28 23:52、dana <dana@dana.is>のメール:
> On 28 Jun 2018, at 02:39, Jun T <takimoto-j@kba.biglobe.ne.jp> wrote:
>> +  _arguments -s -S : $args
> 
> `-A '-*'` would be appropriate for this one.

I didn't add this because "killall -SIGNAL -<TAB>" does not complete
options if -A '-*' is included.
If we do not want to complete options after process names, something
like the following (patch to my previous patch) may be necessary.
A problem of this is now users can't customize by tag-order.


diff --git a/Completion/Unix/Command/_killall b/Completion/Unix/Command/_killall
index a62181c25..d603e6e4a 100644
--- a/Completion/Unix/Command/_killall
+++ b/Completion/Unix/Command/_killall
@@ -69,9 +69,9 @@ else # bsd and darwin
     '-t[limit to processes running on specified tty]: :_ttys -od'
     "-c[with -u or -t, limit to processes matching specified name]: :_process_names $opts"
     '-z[do not skip zombies]'
-    "1: : _alternative 'signals::_signals -p' 'processes-names::_process_names $opts'"
     "*: :_process_names $opts"
+    + '(signal)' -$signals[2,-3]
   )
-  _arguments -s -S : $args
+  _arguments -s -S -A '-*' : $args
 
 fi


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] rewrite _killall
  2018-07-01 16:17   ` Jun T.
@ 2018-07-01 19:14     ` dana
  0 siblings, 0 replies; 6+ messages in thread
From: dana @ 2018-07-01 19:14 UTC (permalink / raw)
  To: Jun T.; +Cc: zsh-workers

On 1 Jul 2018, at 11:17, Jun T. <takimoto-j@kba.biglobe.ne.jp> wrote:
>I didn't add this because "killall -SIGNAL -<TAB>" does not complete
>options if -A '-*' is included.

Oh, yeah. That function was problematic for me when i was messing with _pgrep as
well; i ended up just not using it. I don't know, if hacking around it
introduces other problems i'm sure it's fine to leave it until a nicer solution
is found. I was just being pedantic anyway

dana


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-07-01 19:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-28  7:39 [PATCH] rewrite _killall Jun T
2018-06-28 13:10 ` Jun T.
2018-06-28 14:52 ` dana
2018-06-29 11:45   ` Jun T
2018-07-01 16:17   ` Jun T.
2018-07-01 19:14     ` dana

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).