Skip to content

Instantly share code, notes, and snippets.

@uid0
Created August 6, 2020 05:51
Show Gist options
  • Select an option

  • Save uid0/8f32c104a110eeab26eea62207c08713 to your computer and use it in GitHub Desktop.

Select an option

Save uid0/8f32c104a110eeab26eea62207c08713 to your computer and use it in GitHub Desktop.

Revisions

  1. uid0 created this gist Aug 6, 2020.
    35 changes: 35 additions & 0 deletions onstart.hook
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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')