Writing a task list powerline segment

This is one of these notes to self, in case I want to redo/extend/modify this in the future... Not sure it is of any interest to anybody less nerd, but here it goes for your enjoyment anyway I use powerline since quite some time, it prints fancy prompts in your terminal, where you can plug all kinds of nice nerdy info to be printed, like time, cpu throttle, weather, etc.. If you have a shell that has two prompts (left and right), powerline uses it too. It's easy to install on any linux distro, it's in all packages repositories, and very configurable.

Basically I only used the left segment that shows the current path, and a short right one that shows the current branch if you are in a VCS-controlled folder (git, hg, etc..) and if it's dirty or clean. This is basically how powerlines comes out of the box.

Recently I also discovered taskwarrior, and I quite liked it too. It's a very simple command-line based task list system (I like doing lists) and it has a powerline plugin that shows you the most urgent task to do. I liked that a lot too, having the task under your eyes there kinds of makes you want to get rid of it, so you end up doing it so you can mark it as done, and this has marvelous effects on the processing of your whole list...

I also wanted to sync these tasks somewhere online too, so when you are in the street and you remember something you need to do, you can add it to the list directly from your phone, and forget about it.

Taskwarrior has a server system, but it seemed a bit too much to me, plus I don't have a full-featured server to install the taskwarrior server to (only a standard webhosting service),so this didn't work either.

I use a lot the notes system of nextcloud, pretty easy to use from your cellphone, it has beautiful markdown support, etc. I use that for about everything. So I thought about a very simple task list system, that you could manage from nextcloud's notes app. It's basically a simple text file, where tasks are lines that begin with a . Lines that don't begin with a are not tasks, you can write or organize the way you want:

It is synced to your computer, so locally it's a simple text file that you can edit the way you want (I put an alias in my .zshrc like this so I can just run "taskedit" from the teminal

alias taskedit='nano /home/yorik/Documents/Notes/Tasks.txt'

Then finally I wanted the most urgent task to appear in a powerline segment. It's actually pretty simple. All you need is to write a python script like this:

from powerline.segments import Segment, with_docstringfrom powerline.theme import requires_segment_infoclass ActiveTaskSegment:    def __call__(self, pl, segment_info=None, create_watcher=None):                #pl.debug('Running powerline_tasks')                taskfile = "/home/yorik/Documents/Notes/Tasks.txt"        f = open(taskfile,"rb")        lines = [l for l in f]        f.close()        for l in lines:            if l[0] == "*":                l = l[1:].strip()                l = l.replace("**","")                if "T:" in l:                    t = l.split("T:")                    l = t[0].strip()                    t = t[1].strip()                else:                    t = None                segs = []                if t:                    segs.append()                return segs        return []active_task = with_docstring(    ActiveTaskSegment(),    '''Returns the next active task    Highlight groups used: ``critical:success``    ''')

Then you need to save that file in some place where python can find and import it (for ex. one of the folders indicated by sys.path in python). Then in your .config/powerline/themes/shell/default.json, together with the other segments:

And that's it. powerline_tasks is the name of your .py file. The first task found in the file will be printed, and if there is "T:" in that task, what comes after is printed differently so you can use it to set a deadline or something:

Finally I also wrote a short "taskdone" script to delete the first task when it is done:

#!/usr/bin/pythontaskfile = "/home/yorik/Documents/Notes/Tasks.txt"f = open(taskfile,"rb")lines = [l for l in f]f.close()f = open(taskfile,"wb")done = Falsefor l in lines:    if l.startswith("*") and not done:        done = True        print "Marking task",l.strip(),"as done"    else:        f.write(l.strip()+"n")f.close()