Search code examples
terminalzshhistoryiterm2zshrc

iTerm2 - zsh - keep history of commands when opening a new pane


with zsh on MacOS Catalina, when I split my current window of iTerm2 by opening a new pane, I would like to be able to keep in this new pane the history of commands of previous pane (which is still opened).

Here my current config into ~/.zshrc :

# History
export HISTFILE="$HOME/.zsh_history"
HISTSIZE=10000000
export SAVEHIST=$HISTSIZE
# Avoid duplicates
#setopt HIST_IGNORE_ALL_DUPS
# Remove duplicates in history
function remove_duplicates() {
   echo "$(history 0 | sort -k2 -k1nr | \
   uniq -f1 | sort -n | cut -c8-)" > $HISTFILE
}
remove_duplicates();
setopt inc_append_history

# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend

What is missing or what did I do wrong in this config ?

and Just a question : when I open a new pane, did ~/.zshrc file is executed (I mean sourced like source ~/.zshrc) ?


Solution

  • You can use:

     setopt share_history
    

    According to man zshoptions:

    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).