Feature request: Add post-command hook
DCsunset opened this issue · 5 comments
It would be nice to have some post-command hook in notes so that after executing a command, the user can run a custom script or command.
This idea is inspired by using git to manage the notes from #12. The easiest way to do that is to let the user handle all of this after running any command, so they can detect changes, commit them, and push them if they want.
One easy way to do that is to add an option like POST_COMMAND
in the configurations. That would not bring any breaking changes as well.
If it's a good idea, I'm happy to work on it and open a PR later.
Thanks
Yes, this is an definitely interesting idea!
I wonder a little if this is the best best way of doing this though. Adding a command that's run after each notes command is doable and would cover some cases, but not all cases - e.g. changes to the directory from commands run elsewhere, or even changes from notes open
if you use an EDITOR
that doesn't block until exit (e.g. VS code or similar, where the command just opens the file in an existing window & exits, although yes that's not very unix-y).
How does this compare to implementing command triggers using entr? That would automatically run a command every time any file in the notes repo changes, for any reason, which would solve this problem a bit more generally and independently.
Or are there cases where it's really the notes command being run that you're interested in, not the file changes themselves?
Thanks for your enlightening comment! I agree that using some programs like entr
is a more general and elegant solution. It didn't occur to me until you mentioned it.
I'm not sure whether my original idea is useful in some situations but it doesn't seem necessary now.
Thank you again for your time!
Hi, I recently found that running a command based on file changes may not always be a good idea. For example, if you are making a lot of changes, it's a good habit to save the file from time to time. In this case, it's better to wait until the editor exits and then run some git command because you don't want to commit the intermediate changes.
AFAIK, the UNIX password manager pass
also uses similar logic to run git commit
after the editor exits. Do you think it makes sense to use something like POST_COMMAND
for this scenario?
Sure, that's a fair argument. Just to be clear, the idea is:
- There's an optional
POST_COMMAND
config option, which defaults to nothing - If it's set to a value, that value is run as a command after every modification command exits (so after
notes new
ornotes rm
, but notnotes ls
). - The value is just run directly as-is, with no arguments or anything provided (we can debate expanding that later, e.g. providing env vars you can use to detect the specific change, but it's tricky and I imagine it's not necessary for most use cases)
Yeah? That sounds reasonable to me I think, I'm open to a PR for this if you're keen.
Yeah exactly. I think the modification commands also include append
, mv
, and open
.
I'm happy to submit a PR for this later.