Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] _pick_variant: Update builtin check
- X-seq: zsh-workers 44155
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Subject: Re: [PATCH] _pick_variant: Update builtin check
- Date: Thu, 21 Mar 2019 07:40:53 -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:in-reply-to:user-agent; bh=YHOUNDlIhiLAqhQokobqfB1mSigqgHd0cl/oC4w/Yz0=; b=ZHNH4U4zQNeH9tO7rxr0HPubOdePAAjwUO9QdD4wEJK0jXnihhz62Sc2fUcvys8svv p1NrNGNOury3EYb1paRrKebWXCY/ySU2gWvJYywDHJAS6QER0b5lGrXPQAx7zuxY1FWb ycMCM41Wy4Z9pFiHpmX4Rds6uub+ADEtyshg/nDcIpRP4qgGFCBxE/lNAJvfZ3PT0yu1 aDLVmhHWnnd86E6FFqLPO2Y3BEQJjMDPc1Dt7UqmQH1KwpyFKBNhnpd3181DLMUsqsAN tgRscQK+XO20mL9O3Rcqqc6R+7r835Oi1PvCnabfI/5JwsTRTY5QsbpSSGQDTzNylU7D mjbA==
- In-reply-to: <bc309e59-3f74-4dea-a060-425f429f4430@www.fastmail.com>
- 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> <20190321001636.GA57147@CptOrmolo.darkstar> <bc309e59-3f74-4dea-a060-425f429f4430@www.fastmail.com>
On Thu, Mar 21, 2019 at 07:57:38AM -0400, Daniel Shahaf wrote:
> I understand what you mean in the context of this thread, but I think
> the two uses of the term 'command' might be confusing to someone who
> opens the file in a year or three. How about:
>
> # Precommands which allow their wrapped command to be a builtin.
> # All of these are necessarily builtins or reserved words themselves, but not all builtin precommands are listed here: for one, the 'command' builtin is excluded.
Works for me. Unless there are other comments I'll commit later today.
- Matthew Martin
From 06741ae0671c4a29d2700afa46470a8024ddbefb Mon Sep 17 00:00:00 2001
From: Matthew Martin <phy1729@xxxxxxxxx>
Date: Tue, 19 Mar 2019 20:42:35 -0500
Subject: [PATCH] _pick_variant: Update builtin check
---
Completion/Base/Utility/_pick_variant | 30 ++++++++++++++++++++-------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/Completion/Base/Utility/_pick_variant b/Completion/Base/Utility/_pick_variant
index 9099e3599..872e8f583 100644
--- a/Completion/Base/Utility/_pick_variant
+++ b/Completion/Base/Utility/_pick_variant
@@ -1,9 +1,15 @@
#autoload
-local output cmd pat
+local output cmd pat pre
local -a var
local -A opts
+# Precommands which allow their wrapped command to be a builtin.
+# All of these are necessarily builtins or reserved words themselves,
+# but not all builtin precommands are listed here:
+# for one, the 'command' builtin is excluded.
+local -ar builtin_precommands=(- builtin eval exec nocorrect noglob time)
+
(( $+_cmd_variant )) || typeset -gA _cmd_variant
zparseopts -D -A opts b: c: r:
@@ -13,19 +19,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[(I)builtin] || $+builtins[$opts[-c]] ) )); then
+ (( $+opts[-r] )) && eval "${opts[-r]}=$opts[-b]"
return 0
+elif (( $precommands[(I)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 +50,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
--
2.21.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author