我在一个拥有大量工具的地方工作,需要大量的选择,所以我非常依赖我的shell的历史.我甚至不时地支持它,以确保我不会失去有用的,冗长的命令.
我只是键入了其中一个命令,我想确保它已刷新到历史文件,但我在后台有一个长时间运行的工作,我无法输入exec zsh.在这种情况下我还能做些什么吗?
(当然,我可以将其复制并粘贴到文件中,但是存在flush-history命令会更合乎逻辑.)
pts*_*pts 31
要将shell历史记录写入历史文件,请执行
fc -W
Run Code Online (Sandbox Code Playgroud)
fc有一些有用的标志,看到它们全部man zshbuiltins.
您还可以在每个命令之后完全自动化读取和写入历史文件(从而通过每个运行的zsh自动共享历史文件)setopt -o sharehistory.阅读更多与历史相关的选项man zshoptions.
a p*_*erd 14
我也刚刚发现:
setopt INC_APPEND_HISTORY
Run Code Online (Sandbox Code Playgroud)
来自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).
Run Code Online (Sandbox Code Playgroud)