Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] _pick_variant: Update builtin check
- X-seq: zsh-workers 44151
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Subject: Re: [PATCH] _pick_variant: Update builtin check
- Date: Wed, 20 Mar 2019 19:16:37 -0500
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=ArN0NoOTR0vUlxTHAf+Tb7UQ56s0vCBODHnYGz5Xllo=; b=cSHKMWmkjnjbQqTU8idT2KZC1g2ZnU3tPxIrUIMtvAaSX2OjgxMvGkCWQlv60DpCIR tqv2k7REsad9NtYVUR9bo8cY+2+T6gCxVD7JvRHn0hz6FBKYY0hf4Mq5y1DeC7G0+irb axHQ0+C6ku/UeHTO/hW0YtwgeVOgjeES6aVk4wRyXu4zrPxpKTZgcoS/8WnInzCEOOvt PYl/qVEUwchj8QN/OlvpThoDo9a6DrgOarE0qT8MSL337EPI6wxldI9Dnog+bXbhF3Uw SJG4F8sNbVcfooiKZwsyAiaGsaNYAVIJAWWcW8A9WJctx9WlTQD3w8sdiAsGvw01LY9f 3ySA==
- In-reply-to: <20190320130523.rwpxbzi4u66i2srz@tarpaulin.shahaf.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>, zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20190320020511.GA6739@CptOrmolo.darkstar> <20190320033815.GA22718@CptOrmolo.darkstar> <20190320125238.GA48465@CptOrmolo.darkstar> <20190320130523.rwpxbzi4u66i2srz@tarpaulin.shahaf.local2>
On Wed, Mar 20, 2019 at 01:05:23PM +0000, Daniel Shahaf wrote:
> Matthew Martin wrote on Wed, Mar 20, 2019 at 07:52:39 -0500:
> > There are four booleans in play:
> > - If command (or a non-builtin-preserving precommand) is specified
> > (${#precommands:|builtin_precommands})
> > - If builtin is specified ($+precommands[(r)builtin])
> > - If -b is passed to _pick_variant ($+opts[-b])
> > - If the command is a builtin ($+builtins[$opts[-c]])
> ⋮
> > +++ b/Completion/Base/Utility/_pick_variant
> > @@ -1,9 +1,11 @@
> > #autoload
> >
> > -local output cmd pat
> > -local -a var
> > +local output cmd pat pre
> > +local -a builtin_precommands var
> > local -A opts
> >
> > +builtin_precommands=(- builtin eval exec nocorrect noglob time)
>
> May I suggest a comment here documenting the semantics of this variable?
> For example, why doesn't it list the 'command' precommand (presumably
> becaus that one doesn't preserve builtins, but this info should be in
> the comment, not in the list archives)?
How's
+# Precommands which allow the command to be builtin (unlike command and sudo).
+local -ar builtin_precommands=(- builtin eval exec nocorrect noglob time)
Which of course raises the point that I need to add precommands+=(sudo)
to _sudo (and most users of _normal).
> (And since I'm replying already, style nit: the array could be declared
> readonly.)
Indeed; fixed.
> > (( $+_cmd_variant )) || typeset -gA _cmd_variant
> >
> > zparseopts -D -A opts b: c: r:
> > @@ -13,19 +15,27 @@ while [[ $1 = *=* ]]; do
> > var+=( "${1%%\=*}" "${1#*=}" )
> > shift
> > done
> > -if (( $+_cmd_variant[$opts[-c]] )); then
> > - (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}"
> > - [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1
> > +
> > +if (( ${#precommands:|builtin_precommands} )); then
> > + pre=command
> > +elif (( $+opts[-b] && ( $precommands[(r)builtin] || $+builtins[$opts[-c]] ) )); then
> > + (( $+opts[-r] )) && eval "${opts[-r]}=$opts[-b]"
>
> Should that be «"${opts[-r]}=${(q)opts[-b]}"» with quoting to counter
> the eval? (Also with the preëxisting assignments-in-eval in other lines)
I was planning on switching them all to ${(P)opts[-r]::=...} next.
Thanks for the review!
Messages sorted by:
Reverse Date,
Date,
Thread,
Author