iTerm2 (version 3): Individual history per tab?

If you are using zsh, append these two lines to .zshrc

unsetopt inc_append_history
unsetopt share_history

From zshoptions(1) - Linux man page :

INC_APPEND_HISTORY

This options works like APPEND_HISTORY except that new history lines are added to the $HISTFILE incrementally (as soon as they are entered), rather than waiting until the shell exits.

SHARE_HISTORY

This option both imports new commands from the history file, and also causes your typed commands to be appended to the history file (the latter is like specifying INC_APPEND_HISTORY).

The poster has indicated that this was rather the option he was looking for:

APPEND_HISTORY

If this is set, zsh sessions will append their history list to the history file, rather than replace it. Thus, multiple parallel zsh sessions will all have the new entries from their history lists added to the history file, in the order that they exit.


Extra info to the perfect answer of harrymc.

This is not Iterm2 but a feature of zsh which gets activated by default if you use oh-my-zsh

(see: https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/history.zsh)

So put these in your .zshrc file after source $ZSH/oh-my-zsh.sh (see harrymc's answer)

unsetopt inc_append_history
unsetopt share_history

You can set your HISTFILE environment variable to something unique, but what I do is simply unset it in my .bashrc file:

export HISTFILE=""

but I don't care to keep my history in a file. By unsetting, history is just kept in memory.