Skip to main content
2 of 9
It's generally safer to add things to the end of the prompt command than the beginning. Other commands in PROMPT_COMMAND won't be added to the history, but any command that uses $? needs to be at the front of PROMPT_COMMAND (for instance Powerline).
# avoid duplicates..
export HISTCONTROL=ignoredups:erasedups  
# append history entries..
shopt -s histappend

# After each command, save and reload history
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
Pablo R.
  • 4.8k
  • 1
  • 17
  • 2