add task-note function to bin

This commit is contained in:
Anish L 2022-05-22 23:20:46 +10:00
parent fb48bf2d8d
commit 4a4d19e85c
3 changed files with 57 additions and 2 deletions

View file

@ -117,6 +117,7 @@
# task warrior
t = "task";
ta = "task add";
tn = "task-note";
tm = "task modify";
te = "task edit";
ts = "task sync";
@ -174,8 +175,9 @@
jtl = "journalctl";
# quick ssh
sm = "ssh 10.0.69.4";
ss = "ssh sealight.xyz";
kssh = "kitten +kitty ssh";
sm = "ssh 10.0.69.4"; # box over wireguard
ss = "ssh sealight.xyz"; # helix
sc = "ssh lakhwara.com"; # cube
};
}

View file

@ -0,0 +1,52 @@
#!/usr/bin/env python
"""Manage Taskwarrior notes"""
import argparse
import logging
import os
import sys
import datetime
NOTES_DIR = "~/kitaab/vimwiki/task-notes"
EDITOR = os.environ["EDITOR"]
logging.basicConfig(level=logging.DEBUG)
def write_note(task_id: int):
"""Open `$EDITOR` to take notes about task with ID `task_id`."""
task_uuid = os.popen(f"task _get {task_id}.uuid").read().rstrip()
if not task_uuid:
logging.error(f"{task_id} has no UUID!")
sys.exit(1)
logging.debug(f"Task {task_id} has UUID {task_uuid}")
notes_dir = os.path.expanduser(NOTES_DIR)
os.makedirs(notes_dir, exist_ok=True)
notes_basename = f"{task_uuid}.md"
notes_file = os.path.join(notes_dir, notes_basename)
logging.debug(f"Notes file is {notes_file}")
if not os.path.exists(notes_file):
logging.info("Adding description to empty notes file")
task_description = os.popen(f"task _get {task_id}.description").read()
time = datetime.datetime.now().strftime("%y-%m-%d %H:%M")
with open(notes_file, "w") as f:
f.write(f"%title: {task_description}\n")
f.write(":task:\n")
f.write(f"%date: {time}\n\n")
f.flush()
os.execlp(EDITOR, EDITOR, notes_file)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Write Taskwarrior notes")
parser.add_argument('task_id', metavar='ID', type=int, help="ID of the task to note")
args = parser.parse_args()
write_note(args.task_id)

View file

@ -107,6 +107,7 @@ in
".local/bin/passmenu".source = ./bin/passmenu;
".local/bin/powermenu".source = ./bin/powermenu;
".local/bin/screenshot".source = ./bin/screenshot;
".local/bin/task-note".source = ./bin/task-note;
# ".local/bin/hotplug-monitor.sh".source = ./bin/hotplug-monitor.sh;
};