在多个 zsh shell 中共享历史记录

mic*_*ael 10 zsh

我正在尝试进行设置,zsh以便在不同zsh会话之间共享命令历史记录:

  • 在多个选项卡中
  • 在多个侏儒终端
  • 在不同的screen会话中

我已经把这个 .zshrc

#To save every command before it is executed (this is different from bash's history -a solution):
setopt inc_append_history

#To retrieve the history file everytime history is called upon.
setopt share_history
Run Code Online (Sandbox Code Playgroud)

但这不起作用。

例如,我输入 1 command:gedit afile 然后我去 zsh 并输入history. 我没有看到gedit afile

“setopt”的输出是

 % setopt
nohistbeep
histexpiredupsfirst
histfindnodups
histignorealldups
histignoredups
histignorespace
histnostore
histreduceblanks
histsavenodups
histverify
incappendhistory
interactive
monitor
promptsubst
sharehistory
shinstdin
zle
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Fra*_*sco 10

您的问题的简单答案是您需要设置share_history,您可以这样做:

setopt share_history

因为您显然已经这样做了(并且该选项实际上有效)。我建议你检查:

  • 是否两个shell 都设置了选项;
  • 您是否没有输入带有前导空格的命令(因为histignorespace它们会被忽略)
  • 您是否$HISTFILE在所有 shell 中设置了相同的值?
  • 你是否真的在保存任何历史记录?说,如果你echo 123在 tab-1 中发出。转到选项卡 2,调用history。它在吗?(根据您的问题,不是)。现在发出,fc -R(意味着重新读取历史文件),然后history它现在在那里?如果没有,您可能还想在 tab-1 处调用fc -A-A将强制将您的历史记录附加到文件中)以确保将历史记录写入文件。


小智 10

尝试搜索enter


我测试的是:

  • 打开 2 个 zsh 外壳
  • 转到 zsh shell 1 并执行 echo "something"
  • 转到 zsh shell 2,按enter,然后检查是否看到来自 shell 1 的命令。

就我而言,在按下 之前我不会看到命令enter