iTerm2 - zsh - keep history of commands when opening a new pane
Solution 1:
To share history between sessions, you need to use the SHARE_HISTORY
option. Additionally, you will want to append, rather than overwrite your history file.
setopt SHARE_HISTORY
setopt APPEND_HISTORY
Per the ZSH documentation (Chap. 16 - Options) you should also disable INC_APPEND_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, which should be turned off if this option is in effect). The history lines are also output with timestamps ala EXTENDED_HISTORY (which makes it easier to find the spot where we left off reading the file after it gets re-written).
There's also a few other commands that you may be interested in to deal with your dupes:
-
HIST_NO_STORE
- removes thehistory
command from history. -
HIST_IGNORE_ALL_DUPS
- deletes an older version of added commmand -
HIST_SAVE_NO_DUPS
- when saving the history file, older commands that duplicate newer ones aren't saved