- Code: Select all
export PROMPT_COMMAND="history -n; history -w; history -c; history -r"
shopt -s histappend
There are a couple of differences.
- I set HISTSIZE and HISTFILESIZE - the former sets the size of the in-memory buffer and the latter sets the size of the on-disk file.
- I set PROMPT_COMMAND to save and re-load the history. The reasoning for this command sequence is explained here
- I set HISTIGNORE to common commands from being stored.
- I also set 'h' as an alias for 'history' because I like to save six keystrokes
Something to be aware is that the terminal's history is stored in memory and it is only written to and read from the file when PROMPT_COMMAND is executed. This only happens whenever the prompt is displayed. This means that you need to hit ENTER to update the history.
If you use multiple terminals (which is probably why you'd do this anyway) then you can still experience issues where their histories aren't properly in sync. I don't know why; I just live with it.
If anyone else can suggest anything better it would be good to hear.