I am experiencing the same problem as in this question: The history is shared between my iTerm2 terminal tabs: how can I switch that off?. As the user describes, my history is shared between different tabs and windows in iTerm2, which is very annoying.
I cannot use the solution suggested to the linked question, as I cannot use the setopt
command:
-bash: setopt: command not found
I am using iTerm2 Build 3.0.12 on OS X El Capitan, 10.11.6 and GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15) and tmux 2.3. When I start only tmux, I am also getting the following error message:
tmux
-bash: iterm2_preexec_invoke_cmd: command not found
Deleting my iTerm2 profile/User Settings and starting with a "fresh", non-customized iTerm2 didn't help.
Does one of you maybe have an idea what I could try? Thanks!
Edit:
Here is the output of shopt -p | grep histappend
:
$ shopt -p | grep histappend
shopt -u histappend
and echo $PROMPT_COMMAND
$ echo $PROMPT_COMMAND
history -a; history -c; history -r; date | xargs echo -n >>~/.bash_history_workingdir; echo -n ' - ' >>~/.bash_history_workingdir; pwd | xargs echo -n >>~/.bash_history_workingdir; echo -n ' - ' >>~/.bash_history_workingdir; tail -n 1 /Users/tabea/.bash_eternal_history >>~/.bash_history_workingdir; iterm2_preexec_invoke_cmd
My output for $PROMPT_COMMAND
looks so long, since I changed the default behaviour of the history command, in order to keep an "eternal" bash history (based on this answer). I never suspected that this could cause the weird shared-history-in-iTerm-behaviour, since I have had this in my ~/.bashrc
already before the problem started.
The relevant part of my ~/.bashrc
looks like this:
##########################################################
# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# https://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
export CUSTOM_HISTFILE="~/.bash_history_workingdir" #path of the new history file
export PROMPT_COMMAND="history -a; history -c; history -r; date | xargs echo -n >>$CUSTOM_HISTFILE; echo -n ' - ' >>$CUSTOM_HISTFILE; pwd | xargs echo -n >>$CUSTOM_HISTFILE; echo -n ' - ' >>$CUSTOM_HISTFILE; tail -n 1 $HISTFILE >>$CUSTOM_HISTFILE; $PROMPT_COMMAND"
setopt
is zsh-specific - the bash equivalent isshopt
. Could you runshopt -p | grep histappend
and report back what you see? Also, could you runecho $PROMPT_COMMAND
and report that, too?