When defining a new function in fish, it's possible to make it into an event handler - a function that is automatically run when a specific event takes place.
*Note: event handler is a function, but a function isn't an event handler.
Events that can trigger a handler currently are:
- A signal is delivered
- A job exits
- The value of a variable is updated
fish_prompt
is emitted whenever a new fish prompt is about to be displayed.
fish_preexec
is emitted right before executing an interactive command. The commandline is passed as the first parameter.
fish_posterror
: is emitted right after executing a command with syntax errors. The commandline is passed as the first parameter.
fish_postexec
: is emiited right after executing an interactive command. The commandline is passed as the first parameter. Not emitted if command is empty.
fish_exit
: is emitted right before fish exits.
fish_cancel
: is emitted when a commandline is cleared.
Note: event handlers only become active when a function is loaded, which means you need to otherwise source or execute a function instead of relying on autoloading.