commit abd1c5023d8d6a9807d6b9e9c6b2ef4be0339eca Author: Alex Kelly Date: Mon Mar 3 11:37:04 2025 -0500 initial checkin diff --git a/README.md b/README.md new file mode 100644 index 0000000..d887e92 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# taskwarrior-bw-modify + +This is a taskwarrior on-modify hook to be used to differentiate modifications +coming from the CLI and from other processes. + +## Problem + +I discovered that bugwarrior has a logseq plugin that will update TODO items +from logseq -> taskwarrior. This is great, but the problem is if you try to +close the task from the taskwarrior side, and do not update it on the logseq +side, the task will just come back on the next `bugwarrior pull`. + +This hook addresses the problem by differentiating when you call the taskwarrior +script directly in your shell vs when something else calls it (in my case, +bugwarrior via systemd) + +If you try to close the task on the taskwarrior side, it'll execute taskopen for +the task you are modifying so you may close it in logseq, which will then get +updated on the next pull. + +## Requirements + +* python +* taskwarrior +* taskopen +* logseq configured with the API access + +## Installation + +Link this script in your taskwarrior hooks directory with something like `ln +-nsf /path/to/bugwarrior-check.py ~/.config/task/hooks/on-modify.bugwarrior` diff --git a/bugwarrior-check.py b/bugwarrior-check.py new file mode 100755 index 0000000..ff93770 --- /dev/null +++ b/bugwarrior-check.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +# TaskWarrior hook to keep a logseq->bugwarrior task open, but taskopen it +# so that it may directly be closed in logseq. + +import json +import os +import sys +import subprocess + + +def get_task_data() -> str: + """ + Gets task data from stdin. + + It might be first line on task addition and second line on task + modification. + + :return: str + """ + input_data = sys.stdin.readlines() + + # with open("/tmp/abracadabra", "w") as f: + # f.write(input_data[-1]) + + return input_data[-1] + + +def is_from_cli() -> bool: + """ + Checks for TASK_SRC being set to CLI. If it is, then return True + If it isn't set, or is set to something other than cli, return False + """ + try: + if "cli" in os.environ["TASK_SRC"]: + return True + except KeyError: + return False + return False + + +task_data_raw = get_task_data() + +task_data = json.loads(task_data_raw) + +if "bw" in task_data["tags"] and task_data['status'] == 'completed' and is_from_cli(): + task_data["status"] = "pending" + subprocess.run(["taskopen", task_data["uuid"]], stdout=subprocess.DEVNULL) + +print(json.dumps(task_data, ensure_ascii=False)) +sys.exit(0)