Hooks allow you to run custom script before a note is committed.
Syntax
Hooks are declared using the attribute hook.
Just before a new commit is created, The NoteWriter will try to execute the hook by looking for an executable filename (ignoring the extension) present in .nt/hooks (ex: gist.py).
You can use any language to write your hooks. The JSON representation of the note is available on stdin:
Run
Hooks are automatically triggered when commiting changes using the comand nt commit.
Sometimes, you may want to run a hook manually (useful when developing new hooks). The command nt run-hook allows to execute a hook on a single note (you still need to use nt add to place the note in the index).
Example
Let’s write the hook gist that synchronize the note content (usually stored in a private GitHub repository) with a Gist that can be freely share.
Here is an example of hook written in Python:
This hook is incomplete. Hooks must be idempotent as you don’t want to create a new Gist every time the note is edited. But you now have a good idea of how hooks work.