zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: %! prompt code shows incorrect number
Date: Fri, 21 May 2021 16:55:11 -0700	[thread overview]
Message-ID: <CAH+w=7Z3jw+2+mWEGJq6i81maBkgr4JT-07ypDu6hTbqYsKVNQ@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3Rb+dE94zB6yAhP8n9EZ5b2ms5W2=1y9r2ZYenPGDiDLA@mail.gmail.com>

On Fri, May 21, 2021 at 11:58 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> I've gone with the below hack for now. What I want to be able to do is
> copy the history number from the prompt and paste it back into the
> terminal

I take it this means the history number from some previous prompt.  So
the code in your patch starts at the history number requested, and if
that points to a foreign entry, scans forward until it finds a local
one.

> I don't think there's any existing way to check if a history entry is
> external other than parsing the * out of fc -l output?

It shouldn't need THAT much parsing.  Approximately (in
bracketed-paste-magic idiom):
  historynum=${${(z)"$(fc -lIL $PASTED -1)"}[1]}
  # dash ell eye L for those with sans-serif fonts
  PASTED=$history[historynum]

I don't have shared history to test with, but that should work, with
the caveat that if you paste a number that is less than
$((HISTCMD-HISTSIZE)) you'll just get the oldest local history entry
(which I think is the same with your patch).

Of course if you have thousands of lines of history and paste a really
long-ago number, that's going to use a lot of memory.


      reply	other threads:[~2021-05-21 23:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17  4:48 Mikael Magnusson
2021-05-17  5:05 ` Bart Schaefer
2021-05-21 18:58   ` Mikael Magnusson
2021-05-21 23:55     ` 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=7Z3jw+2+mWEGJq6i81maBkgr4JT-07ypDu6hTbqYsKVNQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=mikachu@gmail.com \
    --cc=zsh-workers@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).