I am running iTerm2 (v 3.2.9) and zsh (v 5.7.1). I normally have 3-4 iTerm tabs opened at the same time and each tab has its own history thanks to the following settings in my .zshrc file
SAVEHIST=10000 # Number of entries
HISTSIZE=10000
HISTFILE=~/.zsh_history
unsetopt inc_append_history
unsetopt share_history
setopt appendhistory
However, when I close and re-open iTerm2 all tabs share the same history (I suppose they are reading from the very same HISTFILE): for example, if I have two tabs (say A and B), where the last command from A is foo and the last command from B is bar, when I close and re-open iTerm2 both tabs see either bar or foo (depending on the latest command which has been run, regardless of A or B) as the last entered command (arrow up key).
My question is: it is possible to keep separate histories even after re-launching iTerm2?
SESSION=foo zsh -i ...... In your .zshrc you do then aHISTFILE=~/.zsh_history.$SESSION. This should reuse this particular history. – user1934428 Dec 28 '22 at 08:44