iTerm2 - zsh - 打开新窗格时保留命令历史记录

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

MacOS Catalina 上使用 zsh,当我通过打开一个新窗格拆分当前的 window 和 iTerm2 时,我希望能够保留在这个新窗格 前一个窗格(仍处于打开状态)的命令历史记录。

这是我当前的配置 ~/.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

此配置中缺少什么或我做错了什么?

只是一个问题:当我打开一个新窗格时,是否执行了 ~/.zshrc 文件(我的意思是来源类似于 source ~/.zshrc)?

您可以使用:

 setopt share_history

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