From: Vincent Lefevre <vincent@vinc17.net>
To: zsh-workers@zsh.org
Subject: Re: issues with saving history to file
Date: Fri, 15 Mar 2024 13:47:50 +0100 [thread overview]
Message-ID: <20240315124750.GB3738413@cventin.lip.ens-lyon.fr> (raw)
In-Reply-To: <CAH+w=7Z8QEX+RCoc4OK=euvt=LJRvU4bzaT92fLHUC7CMcpd8w@mail.gmail.com>
On 2024-03-13 21:52:44 -0700, Bart Schaefer wrote:
> On Wed, Mar 13, 2024 at 8:05 AM Vincent Lefevre <vincent@vinc17.net> wrote:
> > IMHO, HISTFILE should just be unset by default; but if the user sets
> > this parameter, I suppose that the goal is to save the history.
>
> The goal might be to read the history, not to write it.
To read the history? The zshparam(1) man page just says "to save":
HISTFILE
The file to save the history in when an interactive shell exits.
If unset, the history is not saved.
And when I do
cventin:~> zsh -f
cventin% HISTFILE=~/.histfile
I just get the "HISTFILE=~/.histfile" in the history, while
~/.histfile already contains various commands.
> > Without INC_APPEND_HISTORY, the man page doesn't document when
> > precisely the history is saved. For instance, what happens if one
> > has a "print -s ..." in the .zlogout file?
>
> It'd expect it to be lost, because the history is saved before
> .zlogout is read. Try it and let us know. Maybe it dumps core.
It is added to the history, but not saved. With
ls -l .histfile
sleep 1
print -s foo1
print -s foo2
print -s foo3
history
ls -l .histfile
in my .zlogout file, I get
-rw------- 1 vlefevre vlefevre 292 2024-03-15 13:17:11 .histfile
[...]
27 foo1
28 foo2
29 foo3
-rw------- 1 vlefevre vlefevre 292 2024-03-15 13:17:11 .histfile
and indeed, .histfile does not contain these lines.
> > Moreover, with INC_APPEND_HISTORY, "print -s" does not put the entry
> > in the history file immediately, only after the next accept-line.
>
> "print -s" doesn't write to the HISTFILE and isn't documented that
> way. It explicitly says "Place the results in the history list". The
> "history list" is the internal shell history, not the file. The file
> is updated from the internal list either at shell exit or
> (incappendhistory) when a line is entered (i.e., conceptually upon
> accept-line, though in practice upon entering a complete command since
> updating at PS2 would leave an incomplete entry).
The documentation is not explicit.
> You can use the zshaddhistory hook to confirm this.
The documentation of the zshaddhistory hook is not clear. It says
Executed when a history line has been read interactively,
But this is the case for any (possibly empty!) command line,
not just lines read from the history.
Then
but before it is executed.
This is wrong. Empty command lines (which will not be executed) are
also handled by the zshaddhistory hook (contrary to the preexec hook).
And as a consequence, its example
zshaddhistory() {
print -sr -- ${1%%$'\n'}
fc -p .zsh_local_history
}
has the effect to put empty command lines in the history, which
is not the usual behavior.
Moreover, the "fc -p .zsh_local_history" does not seem to work:
no .zsh_local_history file is created.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
next prev parent reply other threads:[~2024-03-15 12:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 15:05 Vincent Lefevre
2024-03-14 4:52 ` Bart Schaefer
2024-03-15 12:47 ` Vincent Lefevre [this message]
2024-03-16 15:41 ` 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=20240315124750.GB3738413@cventin.lip.ens-lyon.fr \
--to=vincent@vinc17.net \
--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).