Skip to content

Instantly share code, notes, and snippets.

@uid0
Created August 6, 2020 05:51
Show Gist options
  • Save uid0/8f32c104a110eeab26eea62207c08713 to your computer and use it in GitHub Desktop.
Save uid0/8f32c104a110eeab26eea62207c08713 to your computer and use it in GitHub Desktop.
Taskwarrior On-Modify Hook for 'stup' integration
import sys
import json
import os
# Hook should extract all of the following for use as Timewarrior tags:
# UUID
# Project
# Tags
# Description
# UDAs
# Make no changes to the task, simply observe.
old = json.loads(sys.stdin.readline())
new = json.loads(sys.stdin.readline())
print(json.dumps(new))
# Extract attributes for use as tags.
tags = [new['description']]
if 'project' in new:
tags.append(new['project'])
if 'tags' in new:
tags.extend(new['tags'])
combined = ' '.join(['"%s"' % tag for tag in tags]).encode('utf-8').strip()
# Started task.
if 'start' in new and not 'start' in old:
os.system('timew start ' + combined + ' :yes')
os.system('stup add -c ' + new['project'] + ' -n "' + new['description'] + '"')
# Stopped task.
elif not 'start' in new and 'start' in old:
os.system('timew stop ' + combined + ' :yes')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment