In reply to: https://lists.gnu.org/r/bug-bash/2024-08/msg00163.html
I've always been annoyed by disappearing history. From reading some threads and a bit of exploration, I think the simplest thing is to add an inc_append_history shopt which is named like the equivalent zsh option. What this does is after a command is parsed, but before it is executed, it is appended to the history file. This basically gives the behavior of PROMPT_COMMAND='history -a' but also ensures the history file is updated if the shell crashes before the command completes. This version *works* but it has some weird effects for HISTFILESIZE - now regardless of whether or not the shell has made any changes, HISTFILESIZE is enforced at shell exit and the history is truncated if necessary. This seems like the simplest behavior, but it's a significant change and there's an argument for gating it behind inc_append_history and also possibly only doing it if the current shell has written anything to history. Also admittedly the patch was all written by ChatGPT Sol and I also had Claude Opus review a bit. This email is all my words. I'm running this version on one of my machines to test it. I've added a test (in the first version, the new shopt broke enforcement of HISTFILESIZE) so there's an explicit test for that case. I want to re-review the code but I think it is reasonable as-is. Does this seem like a good direction for solving the disappearing history problem? Attached is a patch against bash-5.3 patch 15
0001-Add-inc_append_history-shopt-option.patch
Description: Binary data
