How to switch off sharing of history between iTerm2 tabs when setopt command not found
Solution 1:
It's the history -a
part of PROMPT_COMMAND
in your .bashrc
- that's appending to the history file every time a prompt is displayed, whatever tab you're using. A quick fix would be to remove this, so that each tab's session only writes to .bash_history
when the session ends (e.g. when the tab is closed).
I like this behaviour (immediate appends to .bash_history
), and I suspect you may too! A better solution may be to maintain separate histories for each session/tab - one of the answers to this question describes how to achieve that. You could retain immediate appends, but to separate files - one for each session. You would still be able to search your entire bash history with a command like grep "foo" ~/.bash_hist*
. (I've not personally tried this: I use one history file for all sessions, since my normal workflow tends to be in one tab or through screen
, and I archive my /bash_history
periodically into a separate file, as described in this article - which is well worth reading, even if it doesn't address your issue).