From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8880 invoked by alias); 11 Mar 2014 17:05:03 -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: 32471 Received: (qmail 11842 invoked from network); 11 Mar 2014 17:04:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, T_TO_NO_BRKTS_FREEMAIL autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ib/ysO2jE6k/ZUR0KdpfjT3WnXZ872BDwo+PSuawz2A=; b=TGmFxypUHjYU13t+RjSJgUykeUIWqNhL6PYUtMSIl1Sf71nxcGLzb1lq43ZkNibLDb PKaUPwhh8DzAB3nuB9jwSqN9MKYtlZL2GkBTmVwMUrasR3xy/Boal5QzoEyarOM8hhd4 6Cq2E+FEYauaR0KeImiNYn1sY5WJ2yf4OdFIq5ZrnNdXsfBe3iHbKRdYFur9upyXGFoW 5v21IogUbJjwbydYS6D+a8dunwphtgQGhZ/Mk0wFbgnY+LzlO00kqFXItgNkCZbh2v6p AktI8jvL08a2B3k1FkdxBbwBGMA6ndWWx5dW7qTJowGVsXqdxtHsF8Q/yV3tlghejnhF +gjQ== X-Received: by 10.66.25.203 with SMTP id e11mr48450453pag.76.1394557492185; Tue, 11 Mar 2014 10:04:52 -0700 (PDT) From: Kosuke Asami To: zsh-workers@zsh.org Cc: Kosuke Asami Subject: [PATCH 2/3] _pgrep: fix commands used in completion Date: Wed, 12 Mar 2014 02:04:07 +0900 Message-Id: <1394557448-31011-3-git-send-email-tfortress58@gmail.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394557448-31011-1-git-send-email-tfortress58@gmail.com> References: <1394557448-31011-1-git-send-email-tfortress58@gmail.com> The option style in ps command are different between BSD and Linux. For example, 'ps -A co cmd=' command cannot be executed in BSD environment, so zsh completion always shows error like 'ps: illegal argument: co' and cannot be used. --- Completion/Unix/Command/_pgrep | 54 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep index e4bd2e2..15b1f44 100644 --- a/Completion/Unix/Command/_pgrep +++ b/Completion/Unix/Command/_pgrep @@ -8,7 +8,7 @@ arguments=('-P[parent process id]:parent process id:->ppid' '-F[match only in process in pidfile]:files:_files' '-g[match only in process group ids]:group:->pgid' '-G[match only real group id]:group:_groups' - '-j[match only in processes inside jails]' + '-j[match only in processes inside jails]:jail id:->jid' '-M[extract the name list from the specified core]:files:_files' '-N[extract the name list from the specified system]:files:_files' '-s[match only session id]:session id:->sid' @@ -73,21 +73,43 @@ case $state in ;; (sid) + if [[ $OSTYPE == openbsd* ]]; then + break + fi + compset -P '*,' local -a used sid used=(${(s:,:)IPREFIX}) - sid=(${(uon)$(ps -A o sid=)}) + if [[ $OSTYPE == freebsd* ]]; then + sid=(${(uon)$(ps -ax -o sid=)}) + else + sid=(${(uon)$(ps -A o sid=)}) + fi _wanted sid expl 'session id' compadd -S ',' -q -F used $sid ;; + (jid) + compset -P '*,' + + local -a used jid + used=(${(s:,:)IPREFIX}) + jid=(${(uon)$(ps -ax -o jid=)}) + + _wanted jid expl 'jail id' compadd -S ',' -q -F used $jid + ;; + (ppid) compset -P '*,' local -a used ppid used=(${(s:,:)IPREFIX}) - ppid=(${(uon)$(ps -A o ppid=)}) + if [[ $OSTYPE == (freebsd|openbsd|darwin)* ]]; then + ppid=(${(uon)$(ps -ax -o ppid=)}) + else + ppid=(${(uon)$(ps -A o ppid=)}) + fi _wanted ppid expl 'parent process id' compadd -S ',' -q -F used $ppid ;; @@ -97,7 +119,11 @@ case $state in local -a used pgid used=(${(s:,:)IPREFIX}) - pgid=(${(uon)$(ps -A o pgid=)}) + if [[ $OSTYPE == (freebsd|openbsd|darwin)* ]]; then + pgid=(${(uon)$(ps -ax -o pgid=)}) + else + pgid=(${(uon)$(ps -A o pgid=)}) + fi _wanted pgid expl 'process group id' compadd -S ',' -q -F used $pgid ;; @@ -108,11 +134,27 @@ case $state in then ispat="" fi + + local command if (( ${+opt_args[-f]} )) then - _wanted pname expl $ispat'process command line' compadd ${(u)${(f)"$(ps -A o cmd=)"}} + if [[ "$OSTYPE" == freebsd* ]] && (( ${+opt_args[-S]} )); then + command="$(ps -axH -o command=)" + elif [[ "$OSTYPE" == (freebsd|openbsd|darwin)* ]]; then + command="$(ps -ax -o command=)" + else + command="$(ps -A o cmd=)" + fi + _wanted pname expl $ispat'process command line' compadd ${(u)${(f)${command}}} else - _wanted pname expl $ispat'process name' compadd ${(u)${(f)"$(ps -A co cmd=)"}} + if [[ "$OSTYPE" == freebsd* ]] && (( ${+opt_args[-S]} )); then + command="$(ps -axcH -o command=)" + elif [[ "$OSTYPE" == (freebsd|openbsd|darwin)* ]]; then + command="$(ps -axc -o command=)" + else + command="$(ps -A co cmd=)" + fi + _wanted pname expl $ispat'process name' compadd ${(u)${(f)${command}}} fi ;; -- 1.9.0