From: Matthew Martin <phy1729@gmail.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] _pick_variant: Update builtin check
Date: Thu, 21 Mar 2019 07:40:53 -0500 [thread overview]
Message-ID: <20190321124052.GA24497@CptOrmolo.darkstar> (raw)
In-Reply-To: <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@gmail.com>
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
prev parent reply other threads:[~2019-03-21 12:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-20 2:05 Matthew Martin
2019-03-20 3:38 ` Matthew Martin
2019-03-20 12:52 ` Matthew Martin
2019-03-20 13:05 ` Daniel Shahaf
2019-03-21 0:16 ` Matthew Martin
2019-03-21 11:57 ` Daniel Shahaf
2019-03-21 12:40 ` Matthew Martin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190321124052.GA24497@CptOrmolo.darkstar \
--to=phy1729@gmail.com \
--cc=d.s@daniel.shahaf.name \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).