zsh-users
 help / color / mirror / code / Atom feed
* Reverse history search and match for a specific token
@ 2021-09-07 10:53 Eric Smith
  2021-09-07 12:59 ` zzapper
  2021-09-07 21:30 ` Bart Schaefer
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Smith @ 2021-09-07 10:53 UTC (permalink / raw)
  To: Zsh Users

Hi zshellers,

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
$ !?foo?:$
for the last token

How would I match for the token containing `bar`?

Thanks for the tips.

Best wishes
Eric


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Reverse history search and match for a specific token
  2021-09-07 10:53 Reverse history search and match for a specific token Eric Smith
@ 2021-09-07 12:59 ` zzapper
  2021-09-07 21:30 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: zzapper @ 2021-09-07 12:59 UTC (permalink / raw)
  To: zsh-users


On 07/09/2021 11:53, Eric Smith wrote:
> Hi zshellers,
>
> 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
> $ !?foo?:$
> for the last token
>
> How would I match for the token containing `bar`?
>
> Thanks for the tips.
>
> Best wishes
> Eric

echo !?foo?:2 # second

echo !?foo?:0 # first

echo !?foo?:%   # token

echo !?foo?:$   # last

That's all I know await other answers

zzapper



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Reverse history search and match for a specific token
  2021-09-07 10:53 Reverse history search and match for a specific token Eric Smith
  2021-09-07 12:59 ` zzapper
@ 2021-09-07 21:30 ` Bart Schaefer
  1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2021-09-07 21:30 UTC (permalink / raw)
  To: Eric Smith; +Cc: Zsh Users

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-07 21:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 10:53 Reverse history search and match for a specific token Eric Smith
2021-09-07 12:59 ` zzapper
2021-09-07 21:30 ` Bart Schaefer

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).