From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6835 invoked by alias); 14 Sep 2016 23:25:23 -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: 39333 Received: (qmail 9607 invoked from network); 14 Sep 2016 23:25:23 -0000 X-Qmail-Scanner-Diagnostics: from nm30-vm5.bullet.mail.ir2.yahoo.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(212.82.97.83):SA:0(0.0/5.0):. Processed in 0.245166 secs); 14 Sep 2016 23:25:23 -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=0.0 required=5.0 tests=FREEMAIL_FROM,SPF_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: okiddle@yahoo.co.uk X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.mail.yahoo.com designates 212.82.97.83 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1473895150; bh=e89oIkcQ7CGckXeu7xSy2yKqbHEKoe+9N9jNjct45/Y=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=sRds83jX3eTQ7+r10BRbCixtvgVOqpTq4JUO9KmityotIKf50ae9Pm5YW/qpah+m1jxCAHStfksnlR0VVOe+tJP2MRoahUqF1mcVyb/uX48M97XMwShRuc9nYefAw/L+/w1+i/dkokRZvfeclljnV/PgP4rkJec8j+eaoQ2YBLlkf4OvXNgzic/Jx6H8u12cb8OXgc4rE5Jd1sAjl92gTpgWlDGl5qUD7Hmg8W2NjQ2QkizWPJyJ5TOnSOC1ljQcpcI2XgfSAns1AubEO8iO77AGuDDp7VQaTh0SOShGh2DYHk5oyQZJ0teyrD+EBog84gB5bjf3DNKA74a7vjGnZA== X-Yahoo-Newman-Id: 362776.46478.bm@smtp138.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: r1vaaXQVM1k31TSt37.CUcec3NNQPI2FulXZ3R.uE.O.Wxn DDbY5ldheADzQV2RZW0qVgrluLrjlPSZo15E2ewzsLgtfGAurBBqQmELrfj_ Iff..pPEbEjxJ9wd.kaIFf.JTmKynurLxFlFu4N2nZMH3AtnWMscy1liujSK qi.aT0KdY9afoTFvtFvd1QU1RyCa8vFKv8kXgA2iJWG0U.CANb7FpZxhj7pt 9lF8pImh2Nw5FHCUQiVCR7li51HkgizvaDPc8PiNXoM1CQxRf0ZqmRRo.aAy ZC1dRmLMH_ZOLqvYvmL04Vi82AOpF4p3MelnYENFQeCXJIyS8i8.PLOEaHFr 5Tp6gcfzX.MUq72kQbdxakyLNm07YrS9hNhxlsez7rTlpj7ShHnlmMxRjFTr bhj3_JLqiQKDIno00m4g55Dlgk9AArSBfuklmVzLGm8VAuebVLS_4Lx.5W2D 4qdSdKDG5yW2XBDc0sy6RkFN5FZPB7u.3any7G9WKLME0z9BzI1yRIDqP5os C6eeeMscu9qmSlPLQRSuAIQL5ajLguEU9fJcLi9qj45k- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <20160904040142.GA5216@fujitsu.shahaf.local2> From: Oliver Kiddle References: <8eb6dce0-50d7-5ab2-503a-194c1de2e45d@redhat.com> <20160713045957.GA3893@tarsus.local2> <9968da53-c1fd-fa2a-f30c-c74f884d2478@redhat.com> <20160720065832.GA28939@tarsus.local2> <699166a0-b0f0-452c-2561-b7e3cc952062@redhat.com> <25001.1469117569@hydra.kiddle.eu> <20160722071927.GG2521@tarsus.local2> <12554.1472678120@hydra.kiddle.eu> <20160902052342.GA8514@fujitsu.shahaf.local2> <66037.1472828529@hydra.kiddle.eu> <20160904040142.GA5216@fujitsu.shahaf.local2> To: zsh-workers@zsh.org Subject: Re: [PATCH] _virsh (Was: Re: zsh virsh completion) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8950.1473895149.1@hydra.kiddle.eu> Date: Thu, 15 Sep 2016 01:19:09 +0200 Message-ID: <8951.1473895149@hydra.kiddle.eu> On 4 Sep, Daniel Shahaf wrote: > > > > It'd perhaps be useful if > > > > the -p option to _call_program also caused it to add something to > > > > $curcontext when looking up the command style but I'm not sure where > > > > that could be done as we already have the tag and argument fields > > > > filled. Any ideas? > > Perhaps f/sudo? / can't appear in the command name. > +1, sounds good. This particular feature was missed before but is added with the patch below. It is only added for the command and gain-privileges styles, i.e. those checked by _call_program. I also noticed that $words[1] was being updated by _arguments before the code that used it so the patch fixes _sudo. I still need to test this properly together with a real use such as virsh but I don't have virsh or sudo installed on my normal system. > How do we handle the case that >1 precommand wants to set _comp_priv_prefix? At the moment, the last one sets it and overwrites it. Trying to chain them is really going too far. Perhaps _sudo should just not bother at all if _comp_priv_prefix is already set. Oliver diff --git a/Completion/Base/Utility/_call_program b/Completion/Base/Utility/_call_program index 95c761e..9a44f2d 100644 --- a/Completion/Base/Utility/_call_program +++ b/Completion/Base/Utility/_call_program @@ -1,12 +1,15 @@ #autoload +X -local tmp err_fd=-1 +local curcontext="${curcontext}" tmp err_fd=-1 local -a prefix if [[ "$1" = -p ]]; then shift - zstyle -t ":completion:${curcontext}:${1}" gain-privileges && - prefix=( $_comp_priv_prefix ) + if (( $#_comp_priv_prefix )); then + curcontext="${curcontext%:*}/${${(@M)_comp_priv_prefix:#^*[^\\]=*}[1]}:" + zstyle -t ":completion:${curcontext}:${1}" gain-privileges && + prefix=( $_comp_priv_prefix ) + fi fi if (( ${debug_fd:--1} > 2 )) || [[ ! -t 2 ]] diff --git a/Completion/Solaris/Command/_pfexec b/Completion/Solaris/Command/_pfexec index 3f1f3e7..2afaf31 100644 --- a/Completion/Solaris/Command/_pfexec +++ b/Completion/Solaris/Command/_pfexec @@ -25,7 +25,7 @@ _pfexec() { _arguments \ '-P[privileges to acquire]:privspec:_privset' \ '(-):command name: _command_names -e' \ - '*::arguments:{ _comp_priv_prefix=( $words[1] ${(kv)opt_args[-P]} ) ; _normal }' + '*::arguments:{ _comp_priv_prefix=( pfexec ${(kv)opt_args[-P]} ) ; _normal }' } _pfexec "$@" diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo index 21b1ef4..0a212b7 100644 --- a/Completion/Unix/Command/_sudo +++ b/Completion/Unix/Command/_sudo @@ -2,7 +2,7 @@ setopt localoptions extended_glob -local environ e +local environ e cmd local -a args zstyle -a ":completion:${curcontext}:" environ environ @@ -39,6 +39,7 @@ args=( if [[ $service = sudoedit ]] || (( $words[(i)-e] < $words[(i)^(*sudo|-[^-]*)] )) ; then args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' ) else + cmd="$words[1]" args+=( '(-e --edit 1 *)'{-e,--edit}'[edit files instead of running a command]' \ '(-s --shell)'{-s,--shell}'[run shell as the target user; a command may also be specified]' \ @@ -48,7 +49,7 @@ else '(-H --set-home -i --login -s --shell -e --edit)'{-H,--set-home}"[set HOME variable to target user's home dir]" \ '(-P --preserve-groups -i -login -s --shell -e --edit)'{-P,--preserve-groups}"[preserve group vector instead of setting to target's]" \ '(-)1:command: _command_names -e' - '*::arguments:{ _comp_priv_prefix=( $words[1] -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }' + '*::arguments:{ _comp_priv_prefix=( $cmd -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }' ) fi diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index cab665b..260ace4 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4191,7 +4191,9 @@ output is influenced by the permissions it is run with. If the tt(gain-privileges) style is set to true, tt(_call_program) will make use of commands such as tt(sudo), if present on the command-line, to match the permissions to whatever the final command is likely to run -under. +under. When looking up the tt(gain-privileges) and tt(command) styles, +the command component of the zstyle context will end with a slash +(`tt(/)') followed by the command that would be used to gain privileges. ) findex(_combination) item(tt(_combination) [ tt(-s) var(pattern) ] var(tag) var(style) var(spec) ... var(field) var(opts) ...)(