From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16899 invoked by alias); 6 Jun 2016 08:42:28 -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: 38623 Received: (qmail 18852 invoked from network); 6 Jun 2016 08:42:27 -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=r1n1Oeb6zbXizw9nxidX/dmqiaD3S8WMb30bq+novB4=; b=P9n7UEU8HXCMSeDCqnJ1dzv30ZNT0Xjasnuf+M1sTm8rMc3JCRvvSEZgNrrWl5R+AL t8pkCFXVUmPA0nyDqvgq5K9l1hSD/B3Ct/Z0Q8xRjw/qDU9sNiQqcED4XTLibCU7Qwd4 8yty9NJYXAeICZzFY12++CbeuopPDU/COA29S6jAGqd1MBiGF26epV9yhj0u0SwCSxv1 BHS9BPYVIAktzeBj4Yuwd4hQ9k58/bNe8A83VnPkgBywOm8FD/p34MpkUCXAAd5RJoW8 UIWF13GXGudG7WinD3DqAGrMD8lBCJ0t8Dj1vELajpSD4j/BtqnovItkVy/ReNUJc1ao vhxg== X-Gm-Message-State: ALyK8tKi9goc8hmUQPSKOCb38B9ofbgbETU9+Xh5P4vJY/PFY3QxY3W/ecM62l1wOMD2Kfj9 X-Received: by 10.28.25.69 with SMTP id 66mr10255852wmz.39.1465202544602; Mon, 06 Jun 2016 01:42:24 -0700 (PDT) Reply-To: Marko Myllynen To: zsh workers From: Marko Myllynen Subject: [PATCH v2] zsh pidof completion Organization: Red Hat Message-ID: <5755376D.1070702@redhat.com> Date: Mon, 6 Jun 2016 11:42:21 +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 to handle different ps(1) variants then). This version now uses _sequence for -o as suggested by Daniel Shahaf. It might also be nice to provide a generic _process_names type completion like there's one now for _pids but I'll leave it for a separate, future effort. _process_names would offer process names instead of process IDs, there might few potential users for it in the tree already (_killall, _lldb, and _pgrep). --- 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..6361146 --- /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:_sequence -s , _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