Skip to content

Commit c8e5a97

Browse files
sskraslauft
authored andcommitted
Let on-modify.timewarrior rename older intervals too
Until now the hook renamed only the current interval, the @1 upon renaming the task. With this change it tries to find all existing intervals with the same Description and rename them all. Relates to #338 Signed-off-by: Saulius Krasuckas <saulius2@ar-fi.lt>
1 parent 234fbd1 commit c8e5a97

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

on_modify.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import json
3030
import subprocess
3131
import sys
32+
import shlex
3233

3334
# Hook should extract all the following for use as Timewarrior tags:
3435
# UUID
@@ -88,19 +89,21 @@ def main(old, new):
8889
subprocess.call(['timew', start_or_stop] + tags + [':yes'])
8990

9091
# Modifications to task other than start/stop
91-
elif 'start' in new and 'start' in old:
92-
old_tags = extract_tags_from(old)
93-
new_tags = extract_tags_from(new)
92+
old_tags = extract_tags_from(old)
93+
new_tags = extract_tags_from(new)
9494

95-
if old_tags != new_tags:
96-
subprocess.call(['timew', 'untag', '@1'] + old_tags + [':yes'])
97-
subprocess.call(['timew', 'tag', '@1'] + new_tags + [':yes'])
95+
if old_tags != new_tags:
96+
ids = subprocess.check_output(['timew', 'get', 'dom.tracked.ids', old['description']], stderr=subprocess.STDOUT).decode()
97+
ids = shlex.split(ids)
9898

99-
old_annotation = extract_annotation_from(old)
100-
new_annotation = extract_annotation_from(new)
99+
subprocess.call(['timew', 'untag'] + ids + old_tags + [':yes'])
100+
subprocess.call(['timew', 'tag'] + ids + new_tags + [':yes'])
101101

102-
if old_annotation != new_annotation:
103-
subprocess.call(['timew', 'annotate', '@1', new_annotation])
102+
old_annotation = extract_annotation_from(old)
103+
new_annotation = extract_annotation_from(new)
104+
105+
if old_annotation != new_annotation:
106+
subprocess.call(['timew', 'annotate', '@1', new_annotation])
104107

105108

106109
if __name__ == "__main__":

0 commit comments

Comments
 (0)