zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] zsh pidof completion
@ 2016-06-03  9:20 Marko Myllynen
  2016-06-03 20:40 ` Daniel Shahaf
  0 siblings, 1 reply; 3+ messages in thread
From: Marko Myllynen @ 2016-06-03  9:20 UTC (permalink / raw)
  To: zsh workers

Hi,

Below is zsh completions for the pidof(1) command tested with:

pidof from procps-ng 3.3.10

It would seem that pidof is Linux specific but if it's available for
other platforms then we could of course move it under Unix/Command (and
since ps(1) is horribly platform specific we'd need handle different
ps(1) variants then).

Otherwise it works nicely but I'm a bit wondering one thing here: -o
can either repeated on the command line of the PID to be omitted can be
provided as a comma-separated list but I don't see a readily available
method to complete a comma-separated list. No biggie, but if there's
trivial way to do that, please let me know.

It might also be nice to provide a generic _procnames type completion
like there's one now for _pids but I'll leave it for a separate effort
now.

---
 Completion/Linux/Command/_pidof | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Completion/Linux/Command/_pidof

diff --git a/Completion/Linux/Command/_pidof b/Completion/Linux/Command/_pidof
new file mode 100644
index 0000000..0b76027
--- /dev/null
+++ b/Completion/Linux/Command/_pidof
@@ -0,0 +1,24 @@
+#compdef pidof
+
+local curcontext="$curcontext" state line expl ret=1
+typeset -A opt_args
+
+local exargs="-h --help -V --version"
+_arguments -C -s -w \
+  '(- *)'{-h,--help}'[display help information]' \
+  '(- *)'{-V,--version}'[print program version]' \
+  "(-s --single-shot $exargs)"{-s,--single-shot}'[return one PID only]' \
+  "(-c --check-root $exargs)"{-c,--check-root}'[omit processes with different root]' \
+  "(-x $exargs)"-x'[include shells running named scripts]' \
+  "($exargs)"\*{-o+,--omit-pid}'[omit processes with PIDs]:pids:_pids' \
+  '*:process:->procnames' \
+  && return 0
+
+case $state in
+  procnames)
+    # Handle defunct processes and "avahi-daemon:"
+    _wanted values expl process compadd ${${${${${(@)${(f)"$(ps -N --ppid 2 -p 2 o args=)"}%% *}##*/}%:}#\[}%]} && ret=0
+  ;;
+esac
+
+return ret

Thanks,

-- 
Marko Myllynen


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

* Re: [PATCH] zsh pidof completion
  2016-06-03  9:20 [PATCH] zsh pidof completion Marko Myllynen
@ 2016-06-03 20:40 ` Daniel Shahaf
  2016-06-05 14:34   ` Marko Myllynen
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2016-06-03 20:40 UTC (permalink / raw)
  To: Marko Myllynen; +Cc: zsh workers

Marko Myllynen wrote on Fri, Jun 03, 2016 at 12:20:54 +0300:
> Otherwise it works nicely but I'm a bit wondering one thing here: -o
> can either repeated on the command line of the PID to be omitted can be
> provided as a comma-separated list but I don't see a readily available
> method to complete a comma-separated list. No biggie, but if there's
> trivial way to do that, please let me know.

I think you're looking for _sequence:

% compdef '_sequence -s , _pids' f
% f <TAB>

Or perhaps _values (which is what «mount -o <TAB>» uses).

> It might also be nice to provide a generic _procnames type completion
> like there's one now for _pids but I'll leave it for a separate effort
> now.
> 

What would _process_names do?

Cheers,

Daniel


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

* Re: [PATCH] zsh pidof completion
  2016-06-03 20:40 ` Daniel Shahaf
@ 2016-06-05 14:34   ` Marko Myllynen
  0 siblings, 0 replies; 3+ messages in thread
From: Marko Myllynen @ 2016-06-05 14:34 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh workers

Hi,

On 2016-06-03 23:40, Daniel Shahaf wrote:
> Marko Myllynen wrote on Fri, Jun 03, 2016 at 12:20:54 +0300:
>> Otherwise it works nicely but I'm a bit wondering one thing here: -o
>> can either repeated on the command line of the PID to be omitted can be
>> provided as a comma-separated list but I don't see a readily available
>> method to complete a comma-separated list. No biggie, but if there's
>> trivial way to do that, please let me know.
> 
> I think you're looking for _sequence:
> 
> % compdef '_sequence -s , _pids' f
> % f <TAB>

Thanks, that's exactly what I was missing! (It has been added since
5.0.2 which is in use on RHEL 7.)

>> It might also be nice to provide a generic _procnames type completion
>> like there's one now for _pids but I'll leave it for a separate effort
>> now.
> 
> What would _process_names do?

Offer process names instead of process IDs, there might few potential
users for it in the tree already (_killall, _lldb, and _pgrep).

Thanks,

-- 
Marko Myllynen


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

end of thread, other threads:[~2016-06-05 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03  9:20 [PATCH] zsh pidof completion Marko Myllynen
2016-06-03 20:40 ` Daniel Shahaf
2016-06-05 14:34   ` Marko Myllynen

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).