on launch and on exit sync hooks
[sastry/taskwarrior_utils.git] / hooks / on-launch.background-sync.py
1 #!/usr/bin/env python
2
3 # Author: Srikanth Sastry (sastry@csail.mit.edu)
4 #
5 # Description:
6 # This hook runs `task sync` in the background at the start of each task command, except
7 # `task sync` itself.
8 #
9 # Usage: simply copy this file to ~/.tasks/hooks, or whatever your hooks directory is
10 # as specified in you taskrc file.
11 #
12 # Compatibility: This hook uses the Hooks V2 API (https://taskwarrior.org/docs/hooks2.html)
13 # So, it works with TaskWarrior 2.4.3+
14
15 import sys
16 import json
17
18 from subprocess import Popen, PIPE
19
20 args = sys.argv
21 arg_map = {}
22 for arg in args:
23 arg_pair = arg.split(':')
24 if len(arg_pair) != 2:
25 continue
26 arg_map[arg_pair[0]] = arg_pair[1]
27 process = None
28 if arg_map.get('command', '') == 'synchronize':
29 sys.exit(0)
30 else:
31 process = Popen(['task', 'synchronize', 'rc.hooks=off'], stdout=PIPE, stderr=PIPE)
32 print("Synchronizing in the background")
33
34 sys.exit(0)