Every once in a while I discover my zsh
history has been truncated (or maybe lost entirely, difficult to tell), and I have to restore it from backup.
For example, today:
ls -lh ~/.zsh_history
-rw------- 1 stripe staff 32K 21 Feb 10:20 /Users/stripe/.zsh_history
But in my backup from a few days ago:
-rw-------@ 1 stripe staff 203K 17 Feb 22:36 /Volumes/Time Machine Backups/.../Users/stripe/.zsh_history
I have configured zsh
to save lots of history so it shouldn't be a matter of the shell intentionally trimming the file.
unsetopt share_history
setopt inc_append_history
setopt hist_ignore_all_dups
HISTSIZE=500000
SAVEHIST=$HISTSIZE
Has anyone else experienced this and found a way to mitigate it? Is there some zsh
spring cleaning feature I'm unaware of?
Best Answer
ZSH
History file can be truncated/lost/cleaned for multiple reasons those can be:
$HOME
env variable is not defined)Notes
History available setup options
Answer
The following configuration is recommended for this situation (to be setup on
~/.zshrc
file)Alternative
You can use a little script that check the history file size and do restore it from backup when necessary (in
~/.zshrc
)Links
Additional infos are available on this and this questions.