* creating a mnemonic for a history command
@ 2024-05-17 11:03 Allomorphy
2024-05-17 14:00 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Allomorphy @ 2024-05-17 11:03 UTC (permalink / raw)
To: zsh-users
Hallowed Zshers
This is one of the most useful incantations for me:
!?foo?:%
It searches in the history for the latest command that contains the
string `foo' and returns the token (or phrase between spaces) in that
command.
Its a pain to type.
What is an elegant way to set up a mnemonic like say an alias or
something else to type
gimme(foo)
or
!@#foo
Anything that uses less of my limited clock cycles to do this.
🤓
Thanks
E
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: creating a mnemonic for a history command
2024-05-17 11:03 creating a mnemonic for a history command Allomorphy
@ 2024-05-17 14:00 ` Peter Stephenson
2024-05-18 3:11 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2024-05-17 14:00 UTC (permalink / raw)
To: Allomorphy, zsh-users
> On 17/05/2024 12:03 BST Allomorphy <allomorphy@gmail.com> wrote:
> This is one of the most useful incantations for me:
> !?foo?:%
>
> It searches in the history for the latest command that contains the
> string `foo' and returns the token (or phrase between spaces) in that
> command.
>
> Its a pain to type.
> What is an elegant way to set up a mnemonic like say an alias or
> something else to type
> gimme(foo)
> or
> !@#foo
Your best bet is probably to use an editor function --- not a lot
else happens before the history expansion so it's hard to do in the main
shell.
gimme() {
LBUFFER='!?'$LBUFFER
RBUFFER='?:%'$RBUFFER
zle accept-line
}
zle -N gimme
bindkey '^xg' gimme
Type "foo" or whatever on the command line and then hit ^xg.
Note I have not made any attempt to add sanity checks.
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: creating a mnemonic for a history command
2024-05-17 14:00 ` Peter Stephenson
@ 2024-05-18 3:11 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2024-05-18 3:11 UTC (permalink / raw)
To: zsh-users; +Cc: Allomorphy
On Fri, May 17, 2024 at 7:01 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> > On 17/05/2024 12:03 BST Allomorphy <allomorphy@gmail.com> wrote:
> > This is one of the most useful incantations for me:
> > !?foo?:%
> >
> > What is an elegant way to set up a mnemonic like say an alias or
> > something else to type
>
> Your best bet is probably to use an editor function [...]
>
> gimme() {
> LBUFFER='!?'$LBUFFER
> RBUFFER='?:%'$RBUFFER
> zle accept-line
> }
This widget not only retrieves the word, but executes it as a command,
which it seems to me unlikely to be the intended effect? I wonder if
the OP would prefer e.g. complete-word instead of accept-line?
Or perhaps (assuming compinit has run) just escape-slash to invoke
_history-complete-older, if that works well enough?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-18 3:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-17 11:03 creating a mnemonic for a history command Allomorphy
2024-05-17 14:00 ` Peter Stephenson
2024-05-18 3:11 ` 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).