From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5745 invoked by alias); 3 Jun 2016 09:21:00 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 38588 Received: (qmail 5393 invoked from network); 3 Jun 2016 09:20:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:reply-to:to:from:subject:organization:message-id :date:user-agent:mime-version:content-transfer-encoding; bh=uky1TxXO5mKuyDJ5KjtpzeGMym826FoQREc665n/4QY=; b=hc0LB99NlWvFAngW44BABk1GVVoz4p6XyPi8F9G3ADbAwyNPKJwcB6dthxH/p2/Gzk QjeMH3t9ozG5sPREYdRdnhCE/bDhkGN6t2D2gFun4IArCUF2tICfM3NQDhX2V4ksT5Ky 2oe7xMfkBXsmOIM/9oBMGYMjYHM+ZBwE026tNtWj4hJhuvJDVGjwbasOMew4Qevfc9lT jsZyvlkfgq0WvQTyWmyHYS++tmTWLfw5n/CY4TU4yQAHwfAdjbhpCmZSLFWeiA2CpuVv L0EW7qy109D2CCKf5WtFQ9NkrGAtqBrcySnstQ+MEh+a3suOG3ap4DfnVjGWFEo9U0Ll NJIg== X-Gm-Message-State: ALyK8tKWC1H9e4RaBOyZRZWYTgwi/qFq3lbNVbVUK+M8wfWIF7YTMJdsCVOAgii/WJs66VG7 X-Received: by 10.28.145.203 with SMTP id t194mr3113504wmd.88.1464945658121; Fri, 03 Jun 2016 02:20:58 -0700 (PDT) Reply-To: Marko Myllynen To: zsh workers From: Marko Myllynen Subject: [PATCH] zsh pidof completion Organization: Red Hat Message-ID: <57514BF6.6080307@redhat.com> Date: Fri, 3 Jun 2016 12:20:54 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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