2 # Author: Srikanth Sastry (sastry@csail.mit.edu)
5 # This hook runs `task sync` in the background at the end of each task command that mutates
6 # the task db. The list MUTATING_COMMANDS has the list.
8 # Usage: simply copy this file to ~/.tasks/hooks, or whatever your hooks directory is
9 # as specified in you taskrc file.
11 # Compatibility: This hook uses the Hooks V2 API (https://taskwarrior.org/docs/hooks2.html)
12 # So, it works with TaskWarrior 2.4.3+
15 from subprocess
import Popen
, PIPE
17 MUTATING_COMMANDS
= ['add', 'modify', 'done', 'start', 'stop', 'annotate', 'delete']
21 arg_pair
= arg
.split(':')
22 if len(arg_pair
) != 2:
24 arg_map
[arg_pair
[0]] = arg_pair
[1]
26 if arg_map
.get('command', '') in MUTATING_COMMANDS
:
27 process
= Popen(['task', 'synchronize', 'rc.hooks=off'], stdout
=PIPE
, stderr
=PIPE
)
28 print("Synchronizing in the background on exit")