Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] _pick_variant: Update builtin check
- X-seq: zsh-workers 44150
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: [PATCH] _pick_variant: Update builtin check
- Date: Wed, 20 Mar 2019 13:05:23 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm2; bh=BOsIAekcu6VqU6TApHvVbTdQkEKGimfoaHSykqAg BKI=; b=n776mTCDQScFz0c4/X8XM5e8SS+Wbama3ZvwEY5jiMVEslsmvXFfoNe7 jowb9jGdiJB6xvjfRft1MFCBW/QEpYgJcGPFGQ2IOW2m8PUymfQa7EonpxLBxDbj nv2WephrOxxDQFM4g+BCNL1kgah04fDBdpfYXSq5+tYuoX7fCugBt3oGub4Scf++ b9UPJBF5Gntdbc9rAtX8mS8FYI9eZCVlzUf01RBC3scitwHVz2jHOnlonj3FbP4m vdWRKopMpyVSwrO8lZi2qSkDDVGr89r802gKdWaNRlR1lQMAjcU0ut0esKInGUod sW6VbWm0Vcr5frnLQYPJhn16XnxbGQ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=BOsIAekcu6VqU6TApHvVbTdQkEKGimfoaHSykqAgB KI=; b=pHhuSdviAJH374I9AjbyimNxxrwqhqhqYktuvwED5xleA8dBhhofR15ck tl6CYmCY8oWyzYTNnIKwaJN+pn88KWb+jQgrwbe+rK85DD7Cp6WY75SxQ6Tq475b bZnMJKCG2iX6u5yX04P1SzCXFNewOtntc8BL+WtdIsrPrFMjD+9eNSVl1hb5sX94 IxVORYP+wEt17tYiZVVEWy58QVJIoOJF2Rhznf6JOKPbo076svS0pA2w8wGqO76F DQLw7+HZXxiek59c4pk1CZQLyN/uFGIb8zYHG9vFKnimULwqvuDLfIRPRTNgR1Gp bX/Ol1wyvRwV7dc6cjbmA2g5bzuHw==
- In-reply-to: <20190320125238.GA48465@CptOrmolo.darkstar>
- 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>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20190320020511.GA6739@CptOrmolo.darkstar> <20190320033815.GA22718@CptOrmolo.darkstar> <20190320125238.GA48465@CptOrmolo.darkstar>
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)?
(And since I'm replying already, style nit: the array could be declared
readonly.)
> (( $+_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)
> return 0
> +elif (( $precommands[(r)builtin] )); then
> + pre=builtin
> +else
> + # Neither builtin nor command-forcing precommand specified,
> + # so no prefix is needed
> + pre=
> fi
>
> -if [[ $+opts[-b] -eq 1 && -n $builtins[$opts[-c]] ]]; then
> - _cmd_variant[$opts[-c]]=$opts[-b]
> +if [[ $pre != builtin ]] && (( $+_cmd_variant[$opts[-c]] )); then
> (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}"
> + [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1
> return 0
> fi
>
> -output="$(_call_program variant $opts[-c] "${@[2,-1]}" </dev/null 2>&1)"
> +output="$(_call_program variant $pre $opts[-c] "${@[2,-1]}" </dev/null 2>&1)"
>
> for cmd pat in "$var[@]"; do
> if [[ $output = *$~pat* ]]; then
> @@ -36,6 +46,6 @@ for cmd pat in "$var[@]"; do
> done
>
> (( $+opts[-r] )) && eval "${opts[-r]}=$1"
> -_cmd_variant[$opts[-c]]="$1"
> +[[ $pre != builtin ]] && _cmd_variant[$opts[-c]]="$1"
>
> return 1
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author