diff options
author | Yigit Sever | 2020-02-08 16:05:44 +0300 |
---|---|---|
committer | Yigit Sever | 2020-02-08 16:05:44 +0300 |
commit | 77ea150c3d8da6f8e673983351906e1c83478ff5 (patch) | |
tree | 8e0e3d8a4b014ff683dc1afbeaf25f6ff9de28b4 /.task/hooks/on-modify.timewarrior | |
parent | 45e86b7208ede1b7ccadd0441931ac706061994a (diff) | |
download | dotfiles-77ea150c3d8da6f8e673983351906e1c83478ff5.tar.gz dotfiles-77ea150c3d8da6f8e673983351906e1c83478ff5.tar.bz2 dotfiles-77ea150c3d8da6f8e673983351906e1c83478ff5.zip |
track timewarrior hook
Diffstat (limited to '.task/hooks/on-modify.timewarrior')
-rwxr-xr-x | .task/hooks/on-modify.timewarrior | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/.task/hooks/on-modify.timewarrior b/.task/hooks/on-modify.timewarrior new file mode 100755 index 0000000..de21148 --- /dev/null +++ b/.task/hooks/on-modify.timewarrior | |||
@@ -0,0 +1,70 @@ | |||
1 | #!/usr/bin/env python2 | ||
2 | ############################################################################### | ||
3 | # | ||
4 | # Copyright 2015 - 2016, Paul Beckingham, Federico Hernandez. | ||
5 | # | ||
6 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | # of this software and associated documentation files (the "Software"), to deal | ||
8 | # in the Software without restriction, including without limitation the rights | ||
9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | # copies of the Software, and to permit persons to whom the Software is | ||
11 | # furnished to do so, subject to the following conditions: | ||
12 | # | ||
13 | # The above copyright notice and this permission notice shall be included | ||
14 | # in all copies or substantial portions of the Software. | ||
15 | # | ||
16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
17 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
19 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
22 | # SOFTWARE. | ||
23 | # | ||
24 | # http://www.opensource.org/licenses/mit-license.php | ||
25 | # | ||
26 | ############################################################################### | ||
27 | |||
28 | import sys | ||
29 | import json | ||
30 | import os | ||
31 | |||
32 | # Hook should extract all of the following for use as Timewarrior tags: | ||
33 | # UUID | ||
34 | # Project | ||
35 | # Tags | ||
36 | # Description | ||
37 | # UDAs | ||
38 | |||
39 | # Make no changes to the task, simply observe. | ||
40 | old = json.loads(sys.stdin.readline()) | ||
41 | new = json.loads(sys.stdin.readline()) | ||
42 | print(json.dumps(new)) | ||
43 | |||
44 | # Extract attributes for use as tags. | ||
45 | # tags = [new['description']] | ||
46 | tags = [] | ||
47 | |||
48 | if 'project' in new: | ||
49 | project = new['project'] | ||
50 | # tags.append(project) | ||
51 | if '.' in project: | ||
52 | tags.extend([tag for tag in project.split('.')]) | ||
53 | |||
54 | # if 'tags' in new: | ||
55 | # tags.extend(new['tags']) | ||
56 | |||
57 | combined = ' '.join(['"%s"' % tag for tag in tags]).encode('utf-8').strip() | ||
58 | |||
59 | # Started task. | ||
60 | if 'start' in new and not 'start' in old: | ||
61 | os.system('timew start ' + combined.decode() + ' :yes') | ||
62 | |||
63 | # Stopped task. | ||
64 | elif not 'start' in new and 'start' in old: | ||
65 | os.system('timew stop ' + combined.decode() + ' :yes') | ||
66 | |||
67 | # Any task that is active, with a non-pending status should not be tracked. | ||
68 | elif 'start' in new and new['status'] != 'pending': | ||
69 | os.system('timew stop ' + combined.decode() + ' :yes') | ||
70 | |||