Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: %! prompt code shows incorrect number
- X-seq: zsh-workers 48898
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: %! prompt code shows incorrect number
- Date: Fri, 21 May 2021 16:55:11 -0700
- Archived-at: <https://zsh.org/workers/48898>
- In-reply-to: <CAHYJk3Rb+dE94zB6yAhP8n9EZ5b2ms5W2=1y9r2ZYenPGDiDLA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAHYJk3R3jz8VJVTjOd-b3vpSeoBHJe3nc-PoLodnwWnnx_Jt0A@mail.gmail.com> <CAH+w=7azOR7dnsFYVDAHq7kXjKi0AvuZZ1yS13MB-0Cgh3yFrA@mail.gmail.com> <CAHYJk3Rb+dE94zB6yAhP8n9EZ5b2ms5W2=1y9r2ZYenPGDiDLA@mail.gmail.com>
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
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author