zsh-workers
 help / color / mirror / code / Atom feed
From: Marko Myllynen <myllynen@redhat.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: [PATCH] zsh pidof completion
Date: Fri, 3 Jun 2016 12:20:54 +0300	[thread overview]
Message-ID: <57514BF6.6080307@redhat.com> (raw)

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


             reply	other threads:[~2016-06-03  9:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03  9:20 Marko Myllynen [this message]
2016-06-03 20:40 ` Daniel Shahaf
2016-06-05 14:34   ` Marko Myllynen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57514BF6.6080307@redhat.com \
    --to=myllynen@redhat.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).