summaryrefslogtreecommitdiffstats
path: root/.task/hooks/on-modify.timewarrior
diff options
context:
space:
mode:
authorYigit Sever2020-02-08 16:05:44 +0300
committerYigit Sever2020-02-08 16:05:44 +0300
commit77ea150c3d8da6f8e673983351906e1c83478ff5 (patch)
tree8e0e3d8a4b014ff683dc1afbeaf25f6ff9de28b4 /.task/hooks/on-modify.timewarrior
parent45e86b7208ede1b7ccadd0441931ac706061994a (diff)
downloaddotfiles-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.timewarrior70
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
28import sys
29import json
30import 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.
40old = json.loads(sys.stdin.readline())
41new = json.loads(sys.stdin.readline())
42print(json.dumps(new))
43
44# Extract attributes for use as tags.
45# tags = [new['description']]
46tags = []
47
48if '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
57combined = ' '.join(['"%s"' % tag for tag in tags]).encode('utf-8').strip()
58
59# Started task.
60if 'start' in new and not 'start' in old:
61 os.system('timew start ' + combined.decode() + ' :yes')
62
63# Stopped task.
64elif 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.
68elif 'start' in new and new['status'] != 'pending':
69 os.system('timew stop ' + combined.decode() + ' :yes')
70