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

How to make APPENDHISTORY useful?



`APPEND_HISTORY'
     If this is set, zsh sessions will append their history list to the
     history file, rather than overwrite it.  Thus, multiple parallel
     zsh sessions will all have their history lists added to the
     history file, in the order they are killed.

This sounds useful, but in practice it's not very helpful.  Here's why:

Suppose I set HISTSIZE to be more lines than SAVEHIST.  Now every time a
shell exits, it appends its history to the file and then truncates the
file to SAVEHIST lines.  Result: Same as if history weren't appended.

Now suppose I set SAVEHIST to be more lines than HISTSIZE.  Every time a
shell exits, it appends its history to the file, leaving some lines from
other shells at the top.  So far so good.  But when I start a new shell,
it reads in all that history and then truncates it to HISTSIZE.  Result:
Same as if history hadn't been appended.

You get the illusion that something good is happening if you start with
an empty file and run a few shells that don't put SAVEHIST lines into the
history before exiting; but once the file gets full you're back to one of
the states described above.

A logical thought would be to start out with HISTSIZE set to at least as
large as SAVEHIST, and then just before saving the history file, reset
HISTSIZE to something less than SAVEHIST, so that the tail end of this
shell's history would mix with whatever is already in the file.  But that
doesn't work because the history file is written *before* the exit traps
execute and before zlogout files are read, so there's no place to put the
re-assignment to HISTSIZE.

To get the *effect* of reducing HISTSIZE before saving, you have to put
a bunch of `fc' commands in your exit trap or zlogout.  But if you have
to do that anyway, then you can *explicitly* append, so APPEND_HISTORY is
of no benefit in that case.

What am I missing here?



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