zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Allomorphy <allomorphy@gmail.com>, zsh-users@zsh.org
Subject: Re: creating a mnemonic for a history command
Date: Fri, 17 May 2024 15:00:46 +0100 (BST)	[thread overview]
Message-ID: <672456907.1840983.1715954446011@mail.virginmedia.com> (raw)
In-Reply-To: <CA+gDGNwHbKXYVZteQT7j8foEz0dAfae2i82M0Tmf8uEDHU3zwg@mail.gmail.com>

> 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


  reply	other threads:[~2024-05-17 14:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-17 11:03 Allomorphy
2024-05-17 14:00 ` Peter Stephenson [this message]
2024-05-18  3:11   ` Bart Schaefer

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=672456907.1840983.1715954446011@mail.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=allomorphy@gmail.com \
    --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).