zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Eric Smith <es@trustfood.org>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Reverse history search and match for a specific token
Date: Tue, 7 Sep 2021 14:30:13 -0700	[thread overview]
Message-ID: <CAH+w=7ZAUOjHnJwjUowu3etA31grH5LvRUnsUS0LNMALNWAkAQ@mail.gmail.com> (raw)
In-Reply-To: <20210907105355.atgr45xbrjgbjtwr@trustfood.org>

On Tue, Sep 7, 2021 at 3:54 AM Eric Smith <es@trustfood.org> wrote:
>
> I use event history matching a fair amount and can subscript the command to return a specific token like this.
> $ !?foo?:%
> for the token containing foo
>
> How would I match for the token containing `bar`?

If I understand the question, you want the token containing bar from
the most recent command that contains foo, even if some other
intervening command also contains bar?

There's no single expansion that will do this.  What you would need is:

!?foo?:p
!?bar?:%

The :p step duplicates the most recent entry that contains foo,
without executing it, thus making it also the most recent that
contains bar.  You can then use :% to extract  the bar token.

To do it in one step you'd need ${(M)${(z)history[(r)*foo*]}:#*bar*}
but that's four and a half times as much typing.


      parent reply	other threads:[~2021-09-07 21:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 10:53 Eric Smith
2021-09-07 12:59 ` zzapper
2021-09-07 21:30 ` Bart Schaefer [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='CAH+w=7ZAUOjHnJwjUowu3etA31grH5LvRUnsUS0LNMALNWAkAQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=es@trustfood.org \
    --cc=zsh-users@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).