commit 6a0c697a059cc56e8dcb7b964fd85d0756792337 Author: Marty Oehme Date: Mon Mar 31 18:57:42 2025 +0200 initial commit Adds the foundation of a _very_ simple taskopen implementation. diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..24ee5b1 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.13 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7f9d7ab --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "topen" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.13" +dependencies = [ + "tasklib>=2.5.1", +] diff --git a/topen b/topen new file mode 100755 index 0000000..2103006 --- /dev/null +++ b/topen @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# Open or create a note file +# for a taskwarrior task. +# Takes a taskwarrior ID or UUID for a single task. +# Edits an existing task note file, +# or creates a new one. + +import subprocess +import sys +from pathlib import Path + +from tasklib import Task, TaskWarrior + +TASK_DATA_DIR = "~/.local/share/task" + +TASKNOTES_DIR = "~/.local/share/task/notes" +TASKNOTES_EXT = "md" +TASKNOTES_ANNOT = "Note" + +tw = TaskWarrior(data_location=TASK_DATA_DIR) + +args = sys.argv + +if not len(args) == 2: + _ = sys.stderr.write("Please provide task ID as argument.\n") + sys.exit(1) + +given_id = args[1] + +try: + t = tw.tasks.get(id=given_id) +except Task.DoesNotExist: + t = tw.tasks.get(uuid=given_id) + +_ = sys.stderr.write(f"Editing note for: {t['description']} ({t['uuid']})\n") + +notes_file = Path(TASKNOTES_DIR).joinpath(f"{t['uuid']}.{TASKNOTES_EXT}") + +proc = subprocess.Popen(f"nvim {notes_file}", shell=True) +_ = proc.wait() + +def add_annotation_if_missing(task: Task) -> None: + for annot in t["annotations"]: + if annot["description"] == "Note": + return + t.add_annotation(TASKNOTES_ANNOT) + _ = sys.stderr.write(f"Added annotation.\n") + + +add_annotation_if_missing(t) diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..27ab882 --- /dev/null +++ b/uv.lock @@ -0,0 +1,20 @@ +version = 1 +revision = 1 +requires-python = ">=3.13" + +[[package]] +name = "tasklib" +version = "2.5.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/3e/50/3e876f39e31bad8783fd3fe117577cbf1dde836e161f8446631bde71aeb4/tasklib-2.5.1.tar.gz", hash = "sha256:5ccd731b52636dd10457a8b8d858cb0d026ffaab1e3e751baf791bf803e37d7b", size = 23805 } + +[[package]] +name = "topen" +version = "0.1.0" +source = { virtual = "." } +dependencies = [ + { name = "tasklib" }, +] + +[package.metadata] +requires-dist = [{ name = "tasklib", specifier = ">=2.5.1" }]