I am using the following code in my .bashrc file for keeping everything in history when I have multiple tmux panes open:
# Avoid duplicates
HISTCONTROL=ignoredups:erasedups
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend
After each command, append to the history file and reread it
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
I have no problem with this on my linux machine. However on macOS, there is a little problem when using this with tmux specifically (meaning multiple opened asynchronous terminals without tmux work okay).
What then happens is that a new pane in tmux has completely empty history.
Here is a reference comment in question Preserve bash history in multiple terminal windows, showing the same problem on macOS with similar program screen
:
I tried to remove the history -c;
part of the command and now the history in new tmux pane is not empty. However, I am not sure whether it is a working solution and what caveats it might have. Therefore, my main question is what role does the history -c
play and why is it needed.
Note: If you are unable to reproduce the problem, point it out and I will provide os versions, program versions and logs.