Hooks

Hooks are programs you can place in a hooks directory to trigger actions at certain points in zet's execution.

Hooks directory is $ZET_DIR/hooks (.zet/hooks). Zet searches it for executables which are invoked when they're search accordingly. Hooks without executable bits set are ignored.

Zet passes informations about the event which triggered hook via command line arguments. They're documented below. Hooks also receive the same environment as ordinary Zet commands. Notably, $ZET_ROOT and notebook variables parsed from zet.toml are set.

Zet doesn't change a current working directory before invoking hooks, but respects --directory switch.

Hooks can be disabled by using --no-hooks switch or by setting ZET_NO_HOOKS=1 environment variable. Setting the environment variable inside the hook has effect of disabling nesting of hooks for all consecutive Zet commands.

Hook Types

pre-command

This hook is invoked before any non-core Zet subcommand is run, such as zet mv, zet note or zet sync. Core subcommands, such as zet init, zet env or zet api do not trigger this hook.

If pre-command fails by returning a non-zero exit code, it will prevent execution of Zet command itself.

Zet passes the following arguments to it:

  • subcommand which triggered the hook, without the zet- prefix, for example mv, note or sync
  • all arguments which are passed to the subcommand

Arguments are passed exactly as they were passed to Zet (so they might be expanded by the underlying shell, but notably selectors will not be expanded by Zet).

post-command

This hook is invoked after Zet subcommand finishes. It receives a flag, which takes a value of 0 or 1 and denotes whether Zet command was successful or not. 0 means success. Other parameters are the same as in pre-command hook.

Zet won't trigger post-command hook when it was unable to run a command (for example when user invoked a subcommand which doesn't existy).