鱼壳审核

neo*_*f33 1 shell fish

我想在本文之后为Fish Shell编写一个小脚本 - 如何(和为什么)记录整个Bash历史记录.

限制:

  1. PROMPT_COMMAND在Fish中找不到任何BASH 等效物.
  2. 我正在使用自定义的Oh My Fish提示.如果我不必修改自定义鱼类提示,那就太好了.

fah*_*aho 8

你这是错误的方式.您想记录您输入的所有命令吗?默认情况下,Fish会保留所有会话中的最后256k重复数据删除条目,因此您实际上不需要执行任何操作.

如果你想要一个PROMPT_COMMAND等价物,那么,要显示一个提示fish_prompt功能(你已经自定义了),并且每次出现提示时都要做其他事情就是fish_prompt事件,你可以为它定义一个监听器

function name --on-event fish_prompt
    # do stuff
end
Run Code Online (Sandbox Code Playgroud)

如果您希望将执行的所有内容记录到其他文件中,那么就是fish_preexec事件

function log_commands --on-event fish_preexec
    # fish_preexec functions receive the commandline as the argument (see `function --help`)
    echo $argv >> ~/fish.log
end
Run Code Online (Sandbox Code Playgroud)

会工作.