1
votes

I would like to write a small script for the Fish Shell following this article - How (and Why) to Log Your Entire Bash History.

Restrictions:

  1. I didn't find any BASH PROMPT_COMMAND equivalent in Fish.
  2. I am using a custom Oh My Fish prompt. It would be great if I didn't have to modify the custom fish prompt.
1

1 Answers

9
votes

You're going about this the wrong way. You want to log all commands you enter? Fish already by default keeps the last 256k deduplicated entries from all sessions, so you don't actually need to do anything.

If you wanted a PROMPT_COMMAND equivalent, well, to display a prompt there's the fish_prompt function (which you have already customized), and to do something else every time a prompt appears there's the fish_prompt event, which you can define a listener for like

function name --on-event fish_prompt
    # do stuff
end

If you wish to log everything you execute to some other file, there's the fish_preexec event, so

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

would work.