timewarrior icon indicating copy to clipboard operation
timewarrior copied to clipboard

Support hooks

Open boyska opened this issue 2 years ago • 4 comments

I'd like to run a command every time I start/stop a new activity.

I would be ok with a simple command being invoked with no argument: I will then look at timew get to discover the current status and behave accordingly.

boyska avatar Oct 18 '23 14:10 boyska

I would not tie the hook to the start/stop command explicitly, e.g. what about when you start a new tracking with continue? Therefore, I would rather react on certain events than commands.

Drawing inspiration from Taskwarrior, which has defined the following events to trigger appropriate hooks:

  • on-launch, triggered once, after initialization, before any processing occurs
  • on-exit, triggered once, after all processing is complete
  • on-add, triggered separately for each task added
  • on-modify, triggered separately for each task added or modified

Your case would match the on-add or the on-exit event here.

Some further thoughts:

  • Adding a hooks API should be done with extensibility in mind. Using JSON as communication format seems useful. This way, one can convey meta information easily to the hook, e.g. which command has been called, etc.
  • One should start simple, e.g. with the on-exit event, which would call any hook with a payload like this:
    {"command":"<command>"}
    
  • From there, further hook points can be defined/their payload refined.

For reference, issue #49 also requests a way to control Taskwarrior when stopping time tracking

lauft avatar Oct 20 '23 19:10 lauft

I would not tie the hook to the start/stop command explicitly, e.g. what about when you start a new tracking with continue? Therefore, I would rather react on certain events than commands.

totally makes sense!

One should start simple, e.g. with the on-exit event, which would call any hook with a payload like this:

that would totally be enough for my specific usecase, and I agree it makes sense to start simple.

boyska avatar Oct 20 '23 19:10 boyska

Yes, I came up with that requirement today as well. In my case I'd like to trigger my local bluetooth service and power it on and off base on the tag I work with. There are also other scenarios that would be useful for me personally.

Spreadcat avatar Dec 01 '23 10:12 Spreadcat