luc*_*one 20 bash history bashrc
我使用https://unix.stackexchange.com/a/1292/41729 中的答案来启用不同 bash 终端之间的实时共享历史记录。正如上面的答案所解释的,这是通过添加以下内容来实现的:
# avoid duplicates..
export HISTCONTROL=ignoredups:erasedups
# append history entries..
shopt -s histappend
# After each command, save and reload history
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
Run Code Online (Sandbox Code Playgroud)
如果 bash shell 是单独的(例如,使用CTRL+ALT+T
.打开不同的 bash 终端),这可以正常工作。但是,如果我使用tabs
(从打开的终端 `CTRL+SHIFT+T)而不是新窗口,它就不起作用。为什么会有这种行为差异?如何我也可以在各个选项卡之间共享 bash 历史记录吗?
更新:我注意到一个不寻常的行为:如果我输入,CTRL+C
则在任何其他终端(无论是否为选项卡)中输入的最后一个命令都会正确显示。就像 CTRL+C 强制刷新历史记录以便正确共享一样。
例如输出(T1 表示端子 1 和 T2 端子 2):
T1:
ls -lah <enter>
# the list of files and directory is shown
T2:
cd Documents <enter>
T1:
<up> (i.e. I press the up arrow)
ls -lah #i.e the last command in terminal 1 is shown rather than the last of terminal 2
^C (i.e. I press CTRL+C)
<up>
cd Documents #the last command issued in terminal 2 is correctly displayed
Run Code Online (Sandbox Code Playgroud)
希望这可以提供任何提示!
我问了同样的问题,这是我想到的答案......
HISTSIZE=9000
HISTFILESIZE=$HISTSIZE
HISTCONTROL=ignorespace:ignoredups
history() {
_bash_history_sync
builtin history "$@"
}
_bash_history_sync() {
builtin history -a #1
HISTFILESIZE=$HISTSIZE #2
builtin history -c #3
builtin history -r #4
}
PROMPT_COMMAND=_bash_history_sync
Run Code Online (Sandbox Code Playgroud)
当我尝试创建详细的 bash 提示符(显示其他登录次数)时,我在 Yakuake 中也遇到了同样奇怪的行为。选项卡的数量没有增加。我的解决方法是告诉 Yakuakebash
在每个新选项卡中再次运行,本质上是在 bash 中启动 bash。它开始完美地工作。也许它也会对你有帮助。我的盲目猜测是控制台的 GUI 本身加载 bash 配置,然后将它们提供给 bash 实例。也许是为了能够摆弄他们。
归档时间: |
|
查看次数: |
4404 次 |
最近记录: |