HISTFILE=$HOME/.bash_history HISTSIZE=10000 HISTFILESIZE=20000 shopt -s histappend __bash_shared_history() { history -a history -n } __bash_prompt_command_decl=$(declare -p PROMPT_COMMAND 2>/dev/null || printf "") case "$__bash_prompt_command_decl" in declare\ -a*) __bash_shared_history_found=0 for __bash_prompt_command in "${PROMPT_COMMAND[@]}"; do [ "$__bash_prompt_command" = "__bash_shared_history" ] && __bash_shared_history_found=1 done (( __bash_shared_history_found )) || PROMPT_COMMAND+=(__bash_shared_history) ;; *) case ";${PROMPT_COMMAND:-};" in *";__bash_shared_history;"*) ;; *) PROMPT_COMMAND="__bash_shared_history${PROMPT_COMMAND:+; $PROMPT_COMMAND}" ;; esac ;; esac unset __bash_prompt_command_decl __bash_prompt_command __bash_shared_history_found