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

MacOS Terminal.app session save bug



I noticed this recently because I happened to start a shell without my
usual NO_GLOBAL_RCS setting, and finally tracked it down today.

Recent MacOS (beginning around January 2024 but maybe longer ago)
supply a file /etc/zshrc_Apple_Terminal which is sourced from
/etc/zshrc when running in Terminal.app.  I won't describe all the
initialization necessary, but this file adds a zshexit hook that
attempts to write a per-session history file.

The bug is that it uses ">>" to append to the file, in order to
preserve any pre-existing session history.  This runs afoul of
NO_CLOBBER, and if that is set it prints an error message for every
session without saving anything.

I found a related complaint from January 2024 for the Bash variation
of same, to the effect that simultaneously closing multiple
tabs/windows e.g. by shutting down the mac, will cause some of the
bash session management files to be garbled by simultaneous writers.
I've not seen any resolution to that, nor any reports that the same
happens to zsh.

I poked around (not very diligently, I admit) but didn't find any
obvious way to report this to Apple.  If you know one, let me know ...
otherwise, the easiest workaround is probably

  zshexit() { setopt CLOBBER }

because zshexit function is called before all the related hooks.




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