From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27038 invoked from network); 22 Apr 2021 10:56:22 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 22 Apr 2021 10:56:22 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1619088982; b=orAgaSW0jA9OvD8ibXFDOFVYWNyw8kK+UNqzkvuxET4lnZNjdxK2Jm1/2+PCs7oYqWtmf/zVQh KNd40YDbKXyo+saon+N2MzLgAJF3UR35FQG6R0f8YFjtFvYtN4QXchwjqPbplM6eL6IJU1+Jpn 81oGNjvQ3KkRol8Vl1BrNOCD48i1YPlT/9vzugbDihqR67WLzlcvNZ5cVuY+dw0pvfnmRkRz4V ounzcZkgazDSoysji482EgzCtbUbMR2vzwYHBP+McPUqNdNds+BzuG/6YbIYOzH4CHOJHI02ZD 3NDAtoYYNPXWHoqxaM7fbnE/+Dd2L2E5dU3jj7o3em6Jcg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f170.google.com) smtp.remote-ip=209.85.208.170; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1619088982; bh=rJf9DwmSRl7y4Q2iHLdESK24lRDyzSHnGBY3zeLR/SI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:References:To:Cc:In-Reply-To:Date:Subject:MIME-Version: Content-Type:Message-ID:From:DKIM-Signature:DKIM-Signature; b=ZxEvC6oPA6B0ZGcB6ESWyeDNfVlPbV7gcH3NrxmzeG8VXmx1XllECNdxeoxOquxnaixQpLmQVe qij4V/LYZSE59whpQzJcNVp46K+8FG+LorYiZVGEFv5SzHIr28G101KoJRw3v5+G7ifVLliMmi 9vzS2tGdTBSyLFZ0uIKWs8T/byabDRO7uq816CvBjKLtPztehcnQ095kRj+6uU+7r74aE59MfJ EC6yWzVf9NDTQm/NsZVLa95UwO8MDuid1kC9o83xygpemvicd9Ug77v6WEB2Cl+Ku8KlDbuyMk R4lsj7s8V9vPAQhi9wfY4EvXDvty0JiQIgxzFb95MjMQYA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:References:To:Cc:In-Reply-To:Date: Subject:Mime-Version:Content-Type:Message-Id:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=iIXDWw6IoqAYAgXwKZcAOnrXxC2gDFAU69zVbcocA2Y=; b=C2tZxmF/eX3a6BMw2b4AdJ9YIJ X4Pu7u4kykAfnMpC/dIIYuj4eRhtoYUxQX0f4Eza2obONVekmoLJTvMi645QNULSBUwdh1rO2/cvo 9pFyx5pwRoW+qQ1D54DVxoZ9aiZU1xgs8q88yQ6h2QONVzl/u5IoUB56Jl/owvifrBx8j6uccgynP EZPBY0Ttl6zwUXyETf5EA/OTvmqbiCpGpKwLFARaaViWAn+feuUoyRNpCKIYLl/vWj7L90FeZRVNB wT5v48cD3DCHuKe6tqwGCEh63cmyb0q7wVev9skyE8azt7KOtd+LUQLp+FQwBSKCCQzDJ+mGRSasP 1fFyi/5w==; Received: from authenticated user by zero.zsh.org with local id 1lZX0M-000Pzk-F8; Thu, 22 Apr 2021 10:56:18 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f170.google.com) smtp.remote-ip=209.85.208.170; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f170.google.com ([209.85.208.170]:40926) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lZWzn-000Pl9-3h; Thu, 22 Apr 2021 10:55:44 +0000 Received: by mail-lj1-f170.google.com with SMTP id u25so12977448ljg.7 for ; Thu, 22 Apr 2021 03:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=iIXDWw6IoqAYAgXwKZcAOnrXxC2gDFAU69zVbcocA2Y=; b=kq5AOARFXe9na7ajkrZVtMSHegh5aofZLVlWFyXIefWGKygFJLdVoOo0aeDhnq0y8E 8XSlVZYmHHoQD4VPS45r0retpr6YLAvsw8HmzQWTsWd/+ilxkxYuRxsQ1kc0oyTj9HaV hhfKfNNq7nr5K3z+Eq5GCJbyvCOoyo2JOVnX9HmOdgxPBW8YG3OB84xF/+X/OlSNBfGk V2VgHOrbTjqL/F6S819CpEdRd2NO5vOUItk5ZapJ44923ioyDJwagAd0JrOjMWAbBBsh gXQ5vNtJvaZ1z1nqvwtZHtZnmaNtyHcF9dIVcpDwKz7i20dIX7Rr5/gyfrA3Uoxo95Ls 2M6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=iIXDWw6IoqAYAgXwKZcAOnrXxC2gDFAU69zVbcocA2Y=; b=PDfTnnx1p19Abb0nFD/X1uHbEkRjpoZfCaUgK6ZDtvQ1sQXvg6HNomdrG2okeNcIFW ldhaurBwCDF3BXgORDftN1iBtKmne8bYd2RQrAWLGUKqFN0kFhUP7crViuq+/KL317vy T0qvD44t3+DqYgCw/Qma/kAh0Nl/npzohl7zRvuMB+rwxYaunDH0+walZi1dZ7sNcjtI VHZ7EoAfXFHICY9EcMK0Db+UutLGCF3ApWx4xt79/Fb3R0DTr6QA03x2RxA9OT4jILze AXBIYk9Oo64SDA4kz3K/CPqh6lFBSMoKvqNpcQQOJdz8V3pqqMrtEbP0lXG9PtmldNWP XI5w== X-Gm-Message-State: AOAM530kE2pUcSbDlo4CtHnihM8/taDiFa9B1PTlDoXeRgDBJRsHOFTx 48idhExxgvl5AQo5rCzY6/xRjzeLnjszBQ== X-Google-Smtp-Source: ABdhPJzaRGZNchCLWK6lDGJBVK5fjenBDGHBQ00vQ4utfCsPqeUVCwJcptwoTA4XKfHVQokCdX4P3g== X-Received: by 2002:a2e:b44f:: with SMTP id o15mr2097302ljm.19.1619088942207; Thu, 22 Apr 2021 03:55:42 -0700 (PDT) Received: from [192.168.1.15] (hag-tkubng22-50df3e-132.dhcp.inet.fi. [80.223.62.132]) by smtp.gmail.com with ESMTPSA id i8sm243561ljb.43.2021.04.22.03.55.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Apr 2021 03:55:41 -0700 (PDT) From: Marlon Richert Message-Id: <214AC3E9-FFA5-4F39-A918-562682FE3A3B@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_982A8640-0991-4A6B-BD17-0728E1D54B2A" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: [PATCH] Add execute-command() widget function (was Re: [RFC][PATCH] Add change-directory() widget function) Date: Thu, 22 Apr 2021 13:55:35 +0300 In-Reply-To: Cc: Daniel Shahaf , Zsh hackers list To: Bart Schaefer References: <95CDA630-4EE5-4003-8D9C-CCCB9A47F109@gmail.com> <4D587C0C-EB5F-4A58-A0AE-D45E43F432CD@gmail.com> <20210421212717.GE21343@tarpaulin.shahaf.local2> X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Seq: 48651 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: --Apple-Mail=_982A8640-0991-4A6B-BD17-0728E1D54B2A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 New version of the patch attached. Follow-ups to unresolved discussion = points below. On 22 Apr 2021, at 00:58, Bart Schaefer = wrote: > On Wed, Apr 21, 2021 at 2:28 PM Daniel Shahaf = wrote: >> Again, please wrap long lines in your prose. This is the third time = you >> are being asked to do so. I would love to, but I=E2=80=99m not sure when it happens (everything = looks fine on my end) and I haven=E2=80=99t found an explicit setting = for it in my email client. Please let me know if this email has long = lines or not. That would help me figure out which combination of = settings might be causing this. >> As to PUSHD_MINUS and PUSHD_SILENT, it would be better to give an >> example doesn't change them from their default values. Why exactly? > Using "pushd -q ..." avoids the need for PUSHD_SILENT. =20 Except `pushd -q` has the side effect of "the hook function chpwd and = the functions in the array $chpwd_functions are not called" (according = to the manual). That=E2=80=99s not something that I would want when = changing dirs interactively. >>> + # Move the entire current multiline construct into the editor = buffer. This >>> + # function is then aborted and we return to the top-level = prompt, which >>> + # triggers the hook above. >>> + zle .push-line-or-edit >>> + return # Not actually necessary, but for clarity's sake >>=20 >> How is it not necessary? If control flow continued past the = =C2=ABesac=C2=BB, >> code would be executed. >=20 > Flow can't continue past =C2=ABzle .push-line-or-edit=C2=BB because it = invokes > the equivalent of send-break and kills the widget. But I still don't > understand why he wants this here. If I would use push-input instead of push-line-or-edit, the buffer would = not get restored immediately after using the widget. You=E2=80=99d end = up with a blank command line instead. I want it to work the same from = PS2 as it does from PS1. On 22 Apr 2021, at 00:27, Daniel Shahaf wrote: >> +ifnzman(noderef(Miscellaneous))). More precisely, it=20 >=20 > s/it/it:|it+DASH()-/ ? Sorry, I=E2=80=99m new to Yodl. What exactly would that do and why would = we need that here? >> +enumeration( >> +myeit() pushes the buffer onto the buffer stack,=20 >> +myeit() executes the supplied arguments, then=20 >> +myeit() lets the ZLE pop the buffer off the top of the buffer stack = and load=20 >> + it into the editing buffer. >=20 > Should the precise implementation be documented here? If the > implementation strategy is seen as an API promise, it would be more > difficult to change it later. >=20 > Describing what the function actually _does_ (as distinguished from = what > sort of context it's typically used in) is of course relevant; > cf. [workers/45152, fifth hunk]. It=E2=80=99s about the same level of detail as given for run-help, = which-command and push-line-or-edit. >> +You can use this, for example, to create key bindings that let you = instantly=20 >> +change directories, even while in the middle of typing another = command:=20 >> + >> +example(autoload -Uz execute-command >> +setopt autopushd pushdminus pushdsilent >=20 > AUTO_PUSHD is set but not used. If I wouldn=E2=80=99t set it, then the names cd-backward and cd-forward = wouldn=E2=80=99t make any sense anymore. > As to PUSHD_MINUS and PUSHD_SILENT, it would be better to give an > example doesn't change them from their default values. That's again > 45149, which I mentioned just yesterday. Let=E2=80=99s suppose the following: I rewrite the example to use `pushd +1` and `pushd -0`, so it works with = default shell options. A novice user has PUSHD_MINUS in their config (for whatever reason; they = might not even know what it does). They copy-paste the example. Now the widgets won=E2=80=99t work at all as expected. It=E2=80=99s not = even the reverse. Setting PUSHD_MINUS in the example guarantees that it will work out of = the box for novice users. (More advanced users, I=E2=80=99m sure, will = be able to figure out how to modify it to suit their needs.) As for PUSHD_SILENT, as I pointed out above, using `pushd -q` instead = has unwanted side effects. It does not have an interchangeable = alternative. >> +zle -N cd-upward ; cd-upward() { execute-command cd .. } >> +zle -N cd-backward; cd-backward() { execute-command pushd -1 } >> +zle -N cd-forward ; cd-forward() { execute-command pushd +0 } >=20 > s/()/+LPAR()+RPAR()/ so they don't look like yodl macros (and > potentially throw build-time warnings). (For Vim users, the custom > ftplugin sets up concealing which does the reverse replacement while > editing.) Again, sorry, I=E2=80=99m new to Yodl. What exactly are you suggesting? >> +bindkey '^[^[[A' cd-upward; bindkey '^[^[OA' cd-upward >=20 > -1 on using random escape sequences without any explanation of what = they > do and how to find them out. >=20 > Can the symbolic names of these escape sequences be used here? At = least > . > % for k v in "${(@kv)terminfo}" ; [[ $v =3D=3D (*\[A*|*OA*) ]] && = echo $k=20 > cuu1 > kcuu1 > . > if we don't have anything more human-readable than those. (I think = this > was discussed somewhere in the "default zshrc" thread so I won't > elaborate here.) For cuu1 and cuf1, that would work, but ^[[B and ^[[D do not have = entries in terminfo. I don=E2=80=99t think we should use $terminfo[cuu1] = and $terminfo[cuf1] in some examples but then hard-code ^[[B and ^[[D = elsewhere. Hard-coding all of ^[[{A..D} would be more clear. I=E2=80=99m fine using $terminfo for kcuu1, kcud1, kcuf1 and kcub1. = Using $key[Up] would be even better, but we cannot rely on that being = set. --Apple-Mail=_982A8640-0991-4A6B-BD17-0728E1D54B2A Content-Type: multipart/mixed; boundary="Apple-Mail=_FA59061E-930E-42EA-96A7-817A33D37753" --Apple-Mail=_FA59061E-930E-42EA-96A7-817A33D37753 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
New version of the patch attached. Follow-ups to unresolved = discussion points below.


On 22 Apr 2021, at 00:58, Bart Schaefer = <schaefer@brasslantern.com> wrote:
On Wed, Apr 21, = 2021 at 2:28 PM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
Again, please wrap long lines in your prose. =  This is the third time you
are being asked to do = so.

I would love = to, but I=E2=80=99m not sure when it happens (everything looks fine = on my end) and I haven=E2=80=99t found an explicit setting for it in my = email client. Please let me know if this email = has long lines or not. That would help me figure out which combination = of settings might be causing this.


As to PUSHD_MINUS and = PUSHD_SILENT, it would be better to give an
example = doesn't change them from their default values.

Why exactly?


Using "pushd -q ..." avoids the need for PUSHD_SILENT. =  

Except = `pushd -q` has the side effect of "the hook function chpwd and = the functions in the array $chpwd_functions are = not called" (according to the manual). That=E2=80=99s not something = that I would want when changing dirs interactively.


+    # = Move the entire current multiline construct into the editor buffer. = This
+    # = function is then aborted and we return to the top-level prompt, which
+    # triggers the hook above.
+ =    zle .push-line-or-edit
+ =    return  # Not actually necessary, but for = clarity's sake

How is it not = necessary?  If control flow continued past the =C2=ABesac=C2=BB,
code would be executed.

Flow can't continue past =C2=ABzle .push-line-or-edit=C2=BB = because it invokes
the equivalent of send-break and kills = the widget.  But I still don't
understand why he = wants this here.

If I would use push-input instead of = push-line-or-edit, the buffer would not get restored immediately = after using the widget. You=E2=80=99d end up with a blank command = line instead. I want it to work the same from PS2 as it does from = PS1.


On 22 Apr = 2021, at 00:27, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
+ifnzman(noderef(Miscellaneous))). More precisely, = it 

s/it/it:|it+DASH()-/ ?

Sorry, = I=E2=80=99m new to Yodl. What exactly would that do and why would we = need that here?


+enumeration(
+myeit() pushes the buffer onto = the buffer stack, 
+myeit() executes the supplied = arguments, then 
+myeit() lets the ZLE pop the buffer = off the top of the buffer stack and load 
+  it = into the editing buffer.

Should = the precise implementation be documented here?  If the
implementation strategy is seen as an API promise, it would = be more
difficult to change it later.

Describing what the function actually _does_ (as = distinguished from what
sort of context it's typically = used in) is of course relevant;
cf. [workers/45152, = fifth hunk].

It=E2=80=99s about the same level of detail as = given for run-help, which-command and push-line-or-edit.


+You can = use this, for example, to create key bindings that let you = instantly 
+change directories, even while in the = middle of typing another command: 
+
+example(autoload -Uz execute-command
+setopt = autopushd pushdminus pushdsilent

AUTO_PUSHD is set but not used.

If I = wouldn=E2=80=99t set it, then the names cd-backward and cd-forward =  wouldn=E2=80=99t make any sense anymore.


As to PUSHD_MINUS and PUSHD_SILENT, it would be better to = give an
example doesn't change them from their default = values.  That's again
45149, which I mentioned just = yesterday.

Let=E2=80=99s suppose the following:
  • I rewrite the example to use `pushd = +1` and `pushd -0`, so it works with default shell options.
  • A novice user has PUSHD_MINUS in their config (for = whatever reason; they might not even know what it does).
  • They copy-paste the example.
  • Now the widgets won=E2=80=99= t work at all as expected. It=E2=80=99s not even the = reverse.

Setting PUSHD_MINUS in the example guarantees that it will work out = of the box for novice users. (More advanced users, I=E2=80=99m sure, = will be able to figure out how to modify it to suit their = needs.)
As for PUSHD_SILENT, as I pointed out above, using `pushd -q` = instead has unwanted side effects. It does not have = an interchangeable alternative.


+zle -N cd-upward =  ; cd-upward()   { execute-command cd .. }
+zle -N cd-backward; cd-backward() { execute-command pushd -1 = }
+zle -N cd-forward ; cd-forward()  { = execute-command pushd +0 }

s/()/+LPAR()+RPAR()/ so they don't look like yodl macros = (and
potentially throw build-time warnings).  (For = Vim users, the custom
ftplugin sets up concealing which = does the reverse replacement while
editing.)

Again, = sorry, I=E2=80=99m new to Yodl. What exactly are you = suggesting?


+bindkey '^[^[[A' cd-upward; bindkey '^[^[OA' cd-upward

-1 on using random escape = sequences without any explanation of what they
do and how = to find them out.

Can the symbolic names of = these escape sequences be used here?  At least
.
   % for k v in "${(@kv)terminfo}" ; [[ $v =3D=3D= (*\[A*|*OA*) ]] && echo $k 
   cuu1
   kcuu1.
if we don't have anything more = human-readable than those.  (I think this
was = discussed somewhere in the "default zshrc" thread so I won't
elaborate here.)

For cuu1 and cuf1, that would work, but ^[[B and = ^[[D do not have entries in terminfo. I don=E2=80=99t think we should = use $terminfo[cuu1] and $terminfo[cuf1] in some examples but then = hard-code ^[[B and ^[[D elsewhere. = Hard-coding all of ^[[{A..D} would be more clear.

I=E2=80=99m fine using $terminfo for kcuu1, = kcud1, kcuf1 and kcub1. Using $key[Up] would be even better, but we = cannot rely on that being set.


= --Apple-Mail=_FA59061E-930E-42EA-96A7-817A33D37753 Content-Disposition: attachment; filename=0001-Add-execute-command-widget-function.txt Content-Type: text/plain; x-unix-mode=0644; name="0001-Add-execute-command-widget-function.txt" Content-Transfer-Encoding: quoted-printable =46rom caed732b7c9015b2fb692d3c894236b76202a979 Mon Sep 17 00:00:00 2001 From: Marlon Richert Date: Thu, 22 Apr 2021 13:36:56 +0300 Subject: [PATCH] Add execute-command() widget function --- Doc/Zsh/contrib.yo | 34 ++++++++++++++++++++++ Functions/Zle/execute-command | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 Functions/Zle/execute-command diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 8bf1a208e..64388ed70 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -2502,6 +2502,40 @@ arguments: =20 example(zstyle :zle:edit-command-line editor gvim -f) ) +tindex(execute-command) +tindex(cd-upward) +tindex(cd-backward) +tindex(cd-forward) +item(tt(execute-command))( +This function lets you implement a widget that executes a specified = command=20 +(passed as a single string argument) without losing the current command = line,=20 +in a fashion similar to the tt(run-help) and tt(which-command) widgets = (see=20 +ifzman(the subsection bf(Miscellaneous) in zmanref(zshzle))\ +ifnzman(noderef(ZLE widgets standard Miscellaneous))). More precisely, = it=20 +enumeration( +eit() pushes the buffer onto the buffer stack, then +eit() executes the supplied argument string, then=20 +eit() lets the ZLE pop the buffer off the top of the buffer stack and = load=20 + it into the editing buffer. +) + +You can use this, for example, to create key bindings that let you = instantly=20 +change directories, even while in the middle of typing another command:=20= + +example(autoload -Uz execute-command +setopt autopushd pushdminus pushdsilent +zle -N cd-upward ; cd-upward() { execute-command -- 'cd ..' } +zle -N cd-backward; cd-backward() { execute-command -- 'pushd -1' } +zle -N cd-forward ; cd-forward() { execute-command -- 'pushd +0' } +bindkey '^[[A' cd-upward # Alt-Up in raw mode +bindkey "$terminfo[kcuu1]" cd-upward # Alt-Up in app mode +bindkey '^[-' cd-backward # Alt-Minus +bindkey '^[=3D' cd-forward # Alt-Equals) + +Note that widgets created with this function cannot be used inside a = tt(select)=20 +loop or tt(vared). Under those circumstances, the function does nothing = and=20 +returns non-zero. +) tindex(expand-absolute-path) item(tt(expand-absolute-path))( Expand the file name under the cursor to an absolute path, resolving diff --git a/Functions/Zle/execute-command = b/Functions/Zle/execute-command new file mode 100644 index 000000000..4014fa854 --- /dev/null +++ b/Functions/Zle/execute-command @@ -0,0 +1,54 @@ +# Lets you implement widgets that can execute arbitrary commands = without losing +# the current command line, in a fashion similar to 'run-help' and +# 'which-command' widgets. See the manual for examples. + +zmodload -F zsh/zutil b:zparseopts +autoload -Uz add-zle-hook-widget + +case $CONTEXT in + ( start ) # PS1 + ;; + ( cont ) # PS2 + # Add a one-time hook that will re-run this widget at the top-level = prompt. + local hook=3Dline-init + local func=3D${(q):-:${(%):-%N}:$hook:$WIDGET} + eval "$func() { + # Make sure we don't run twice. + add-zle-hook-widget -d $hook $func + + # Don't leave anything behind. + zle -D $func + unfunction $func + + # Use -w to ensure \$WIDGET is set to our original widget, not = the hook. + # This doesn't matter at present, but might matter in future or = if this + # code gets copy-pasted elsewhere. + zle ${(q)WIDGET} -w + }" + add-zle-hook-widget $hook ${(Q)func} + + # Move the entire current multiline construct into the editor = buffer. This + # function is then aborted and we return to the top-level prompt, = which + # triggers the hook above. + # We don't use .push-input here, because that would result in a = blank + # buffer afterwards. + zle .push-line-or-edit + return # Command flow never actually gets here. See above. + ;; + ( * ) + # We don't want this to be used in a select loop or in vared: + # * At a select prompt, the command wouldn't be "executed"; it'd be = fed to + # select as the value of the selection. + # * In vared, it would replace the contents of the variable with = the + # command string and then exit vared. + return 75 # EX_TEMPFAIL; see `man 3 sysexits`. + ;; +esac + +# Push the current buffer onto the buffer stack and clear the buffer. = The ZLE +# will auto-restore it at the next top-level prompt. +zle .push-line + +zparseopts -D - # Remove - or -- argument. +BUFFER=3D"$1" +zle .accept-line --=20 2.31.1 --Apple-Mail=_FA59061E-930E-42EA-96A7-817A33D37753 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii

--Apple-Mail=_FA59061E-930E-42EA-96A7-817A33D37753-- --Apple-Mail=_982A8640-0991-4A6B-BD17-0728E1D54B2A--