serhii.net

In the middle of the desert you can say anything you want

09 Feb 2022

taskwarrior getting currently active task

I want to create a qtile widget to show the currently running taskwarrior task in my statusbar.

Bash way

task  rc.verbose=nothing rc.color=off a

The report in ~/.taskrc is:

# Currently active name
report.a.description='Currently active task'
report.a.columns=id,description,project
report.a.labels=ID,D,P
report.a.filter=+ACTIVE

Ugly draft Python way

Found out about taskw, looks really nice. First draft implementation:

from taskw import TaskWarrior

def pretty_task(act):
    return f"{act['id']}/{act['description']}"


def get_task():
    w = TaskWarrior()
    tasks = w.load_tasks()['pending']
    act = [t for t in tasks if "start" in t]
    #  act = [t for t in tasks]
    return '_'.join([pretty_task(a) for a in act])

Returns:

19:04:27 ~/.config/qtile/cfgs/ 130
> python3 get_task.py
98/Add Taskwarrior to qtile statusbar through python binding

Couldn’t find a way to access taskwarrior’s “virtual tags” (+ACTIVE…), so I used the fact that "start" exists in the dictionary only if the task started.

Nel mezzo del deserto posso dire tutto quello che voglio.