Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Proof of concept for a Taskwarrior on-exit hook that manages a git repository in ~/.task
#!/usr/bin/env python
# PoC: Manage a git repository in ~/.task that gets updated on changes.
# Only and are included by default.
# You can use "git add" to add whatever files you want to track in your
# task folder.
# Inspired by
# Works with any Taskwarrior version that supports hooks.
# Needs Taskwarrior 2.4.3 in order to show fancy commit messages.
# NOTE: Little to no error handling. This is a PoC, remember?
import os
import subprocess
import sys
TASK_DIR = os.path.dirname(__file__) + os.sep + os.pardir
c = {}
if len(sys.argv) > 1:
c = {k:v for k, v in (s.split(":", 1) for s in sys.argv[1:])}
if 'args' not in c:
c['args'] = "Taskwarrior version too old, no info available."
if not os.path.isdir(TASK_DIR + os.sep + ".git"):"git init".split())
with open(".gitignore", "w") as f:
f.write("*\n")"git add -f .gitignore".split())["git", "commit", "-mInitial log"])
if"git diff --exit-code --quiet".split()) != 0:"git commit -a".split() + ["-m" + c['args']])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment