我在一个需要大量选项的工具中工作,因此我非常依赖于我的shell历史记录。我甚至会定期备份它,以确保我不会失去有用的长命令。
我刚刚输入了其中一个命令,并希望确保它被刷新到历史文件中,但我有一个正在后台运行的长时间任务,不能键入exec zsh
。在这种情况下,我还能做些什么吗?
(当然,我可以将其复制并粘贴到文件中,但存在一个flush-history
命令会更有逻辑性。)
fc -W
fc
有一些有用的标志,可以在 man zshbuiltins
中查看所有标志。
你也可以通过输入 setopt -o sharehistory
来完全自动化地读取和写入每个命令后的历史文件(因此自动与运行中的每个 zsh 共享您的历史文件)。在 man zshoptions
中阅读更多关于历史记录的选项。
我也刚刚发现:
setopt INC_APPEND_HISTORY
来自于 man zshoptions
:
INC_APPEND_HISTORY
This options works like APPEND_HISTORY except that new history
lines are added to the $HISTFILE incrementally (as soon as they
are entered), rather than waiting until the shell exits. The
file will still be periodically re-written to trim it when the
number of lines grows 20% beyond the value specified by $SAVE-
HIST (see also the HIST_SAVE_BY_COPY option).
然后使用
fc -R
如何在已有的 zsh shell 中读取历史记录(写入后)。
HISTSIZE=1000
if (( ! EUID )); then
HISTFILE=~/.zsh_history_root
else
HISTFILE=~/.zsh_history
fi
SAVEHIST=1000