Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Re-reading history from ZLE
On Wed, Aug 24, 2022 at 8:26 AM martin f krafft <madduck@xxxxxxxxxxx> wrote:
>
> Is there a reason why reset-prompt shouldn't re-initialise ZLE's understanding of history?
History isn't updated until ZLE exits (accept-line, etc.). The
"current event" is not actually in the history, it's treated specially
as a pending entry; almost anything you do with a widget (including
print -s) is effectively part of that pending entry.
There is one exception: The "fc" command updates the history
immediately. So if you rewrite your widget as ...
_test_hist() {
fc -R =(<<<"echo foo")
zle -M "The last line of history is now 'echo foo'
zle reset-prompt
}
... then you'll get what you want, including seeing the value of %h
(history number) in your prompt increase by one.
Beware that "fc -R" may ignore lines beginning with ": " because it's
attempting to intuit whether the file is using extended history
format, and if you're adding a multi-line entry you'll want to prefix
all the newlines with backslashes, etc.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author