Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: %! prompt code shows incorrect number

On Fri, May 21, 2021 at 11:58 AM Mikael Magnusson <mikachu@xxxxxxxxx> 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

> 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

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.

Messages sorted by: Reverse Date, Date, Thread, Author