Prompt_command to reload from .bash_history

Solution 1:

The history -a command only appends to the history file. This doesn't affect any shell session unless you also read from it. So, what you're looking for is:

PROMPT_COMMAND="history -a; history -r"

As explained in help history:

  -r    read the history file and append the contents to the history
        list

This way, you will first append your current shell's history to $HISTFILE and then read from it, importing the history appended from any other shell instance into the current one.

Note that if you run a command in one terminal, it won't appear in the history of another until you run a command in the second. The $PROMPT_COMMAND is run before a prompt is shown, so if the second terminal is just open and sitting there, it won't read the new command run in the first one until you run something in the second and a new prompt is shown.