I use a zsh precmd() along the lines of
echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(fc -ln -1)" >> ~/bash/bash-history-$(date "+%Y-%m-%d").log;
Should be doable with bash's PROMPT_COMMAND if you are still on bashI use a zsh precmd() along the lines of
echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(fc -ln -1)" >> ~/bash/bash-history-$(date "+%Y-%m-%d").log;
Should be doable with bash's PROMPT_COMMAND if you are still on bashLines 11-21 can be ignored, they detect if the folder you were in got moved/deleted from another shell, to avoid the confusing behavior you get in that case.
Possibly worth noting for others that you'd want to think this through if you're using any of the history eliding options(hist_ignore_space² for example), as one history file may contain secrets when you're really expecting that it wouldn't.
There is also a better interface to work with hook functions through the add-zsh-hook mechanism³, which allows stacking multiple hook functions together.
¹ https://zsh.sourceforge.io/Doc/Release/Functions.html#index-...
² https://zsh.sourceforge.io/Doc/Release/Options.html#History
³ https://zsh.sourceforge.io/Doc/Release/User-Contributions.ht...
Already done, with also PS0 and a sqlite backend: https://github.com/csdvrx/bash-timestamping-sqlite