pimterry / notes

:pencil: Simple delightful note taking, with more unix and less lock-in.
https://github.com/pimterry/notes
MIT License
1.24k stars 82 forks source link

Feature request: Add post-command hook #87

Closed DCsunset closed 1 year ago

DCsunset commented 2 years ago

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

pimterry commented 2 years ago

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?

DCsunset commented 2 years ago

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!

DCsunset commented 2 years ago

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?

pimterry commented 2 years ago

Sure, that's a fair argument. Just to be clear, the idea is:

Yeah? That sounds reasonable to me I think, I'm open to a PR for this if you're keen.

DCsunset commented 2 years ago

Yeah exactly. I think the modification commands also include append, mv, and open.

I'm happy to submit a PR for this later.