将命令追加到历史记录而不删除最后一个命令

时间:2020-02-18 17:58:54

标签: bash shell

我用fzf做很多事情。我经常会用管道输送fzf的输出,并用结果运行另一个命令。但是,我经常想将该命令保存到我的bash_history中,因此我可以再次运行它,而无需再次使用fzf查找该项目。为此,我使用了history -s命令。来自help history的输出:

history: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
    Display or manipulate the history list.
...
      -s    append the ARGs to the history list as a single entry

但是,它似乎也删除了历史记录中的最后一项(即包含fzf的命令)。我发现here的bash-builtins手册页对此提供了支持。

...
       history -s arg [arg ...]
...
              -s     Store  the  args in the history list as a single entry.  The last command in
                     the history list is removed before the args are added.

是否有防止删除最后一条命令的方法?如果可能的话,我想同时在我的历史记录中同时显示fzf命令

其他详细信息

  • Bash版本:5.0.11(1)-发行版
  • OS:macOS Mojave 10.14.6(18G3020)

0 个答案:

没有答案