Fish-shell: [SOLVED] fish equivalent to precmd/PROMPT_COMMAND ?

Created on 16 Apr 2016  ·  3Comments  ·  Source: fish-shell/fish-shell

Is there a fish equivalent for precmd (zsh) / PROMPT_COMMAND (bash)?

I'm looking for a way to store a more comprehensive history with path, date and command in a separate log file

question

Most helpful comment

There's a variety of ways to do this. Fish's prompt is a bit of code in a function called fish_prompt. You can modify it via funced fish_prompt and then save those changes to disc with funcsave fish_prompt (this will store it in ~/.config/fish/functions/fish_prompt.fish, which you can also modify directly if you so choose).

Otherwise, there's the fish_prompt event that will be fired just before a prompt. You can write a listener for it like

function dostuff --on-event fish_prompt
    # do your stuff
end

Note that this cannot be saved in the functions directory as those are autoloaded. Save it in config.fish, a file that gets sourced by it or (in the next fish release) ~/.config/fish/conf.d (in a file ending in ".fish").

There's also the fish_preexec and fish_postexec events that will be fired right before/after a job, respectively.

All 3 comments

There's a variety of ways to do this. Fish's prompt is a bit of code in a function called fish_prompt. You can modify it via funced fish_prompt and then save those changes to disc with funcsave fish_prompt (this will store it in ~/.config/fish/functions/fish_prompt.fish, which you can also modify directly if you so choose).

Otherwise, there's the fish_prompt event that will be fired just before a prompt. You can write a listener for it like

function dostuff --on-event fish_prompt
    # do your stuff
end

Note that this cannot be saved in the functions directory as those are autoloaded. Save it in config.fish, a file that gets sourced by it or (in the next fish release) ~/.config/fish/conf.d (in a file ending in ".fish").

There's also the fish_preexec and fish_postexec events that will be fired right before/after a job, respectively.

@gawells, did this answer your question?

Yes, it did thanks

Was this page helpful?
0 / 5 - 0 ratings