Skip to content

Instantly share code, notes, and snippets.

@wbsch
Last active September 4, 2015 05:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wbsch/164757889ba4554df359 to your computer and use it in GitHub Desktop.
Save wbsch/164757889ba4554df359 to your computer and use it in GitHub Desktop.
Proof of concept for a Taskwarrior on-add hook that allows for "inline tags" when adding tasks
#!/usr/bin/env python
#
# PoC for "inline tags", as described in TW-1357
# https://bug.tasktools.org/browse/TW-1357
#
# Turns
# $ task add I saw @bob in the @garden
# Into the equivalent of
# $ task add I saw bob in the garden +bob +garden
import json
import re
import sys
t = json.loads(sys.stdin.readline())
inline_tags = re.findall(r"(?:\A| )@([^ ]+)", t['description'])
for newtag in inline_tags:
if 'tags' not in t:
t['tags'] = [newtag]
elif newtag not in t['tags']:
t['tags'].append(newtag)
t['description'] = re.sub(r"(\A| )@([^ ]+)", r"\1\2", t['description'])
print(json.dumps(t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment