Skip to content

Instantly share code, notes, and snippets.

@vhbui02
Created April 29, 2023 02:24
Show Gist options
  • Save vhbui02/3eea65043234b909ed63a8ba1f36c8aa to your computer and use it in GitHub Desktop.
Save vhbui02/3eea65043234b909ed63a8ba1f36c8aa to your computer and use it in GitHub Desktop.
[Event Handlers in Fish] linked functions with event #fish

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

Some noted event handlers

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment