-
-
Save linuxcaffe/ed679d8897bca2b66daed7361d673579 to your computer and use it in GitHub Desktop.
Proof of concept for a Taskwarrior on-exit hook that manages a git repository in ~/.task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# PoC: Manage a git repository in ~/.task that gets updated on changes. | |
# Only pending.data and completed.data are included by default. | |
# | |
# Inspired by https://gist.github.com/Unode/9366218 | |
# | |
# Needs Taskwarrior-NOT_PUBLIC_YET in order to work. | |
# | |
# 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) > 2: | |
c = {k:v for k, v in (s.split(":", 1) for s in sys.argv[2:])} | |
if 'args' not in c: | |
args['c'] = "Taskwarrior version too old, no info available." | |
os.chdir(TASK_DIR) | |
if not os.path.isdir(TASK_DIR + os.sep + ".git"): | |
subprocess.call("git init".split()) | |
with open(".gitignore", "w") as f: | |
f.write("*\n") | |
subprocess.call("git add -f .gitignore pending.data completed.data".split()) | |
subprocess.call(["git", "commit", "-m'Initial log'"]) | |
if subprocess.call("git diff --exit-code --quiet".split()) != 0: | |
subprocess.call("git commit -a".split() + ["-m'" + c['args'].replace("'", "") + "'"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment