Todo lists and SED tricks

technology.pngWhat else is insomnia for besides programming?

Anytime my todo list (in a plain text file, using this script for management) is out of sight, I start forgetting stuff. But because I like to capture everything in my todo list, they get really long. I use the plain text todo list, and I’d previously come up with a way of choosing what bits of your todo txt file you wanted to see.

But what if you want to see the whole thing? In columns? (I use conky with linux, but the same principle should work with Samurize or Rainmeter – you just need access to the programs sed, fold, and column. I don’t know if fold and column is in cygwin or not – but they’re in OSX as well as Linux. You can also find a windows port of sed here. If you know for Windows/Cygwin, let me know!)

So you have your todo list as a single column, UNNUMBERED text file. (The todo script numbers it for you.) Here’s the magic line of code:
sed = /home/user/todo/todo.txt | sed ‘N;s/n/ /’ | fold |sed -e ‘s/[ t]$//’ | sed -e ‘/^[0-9]/!s/[ t]/ /’| sed -e :a -e ‘s/^.{1,80}$/& /;ta’|column -c 200

Looks scary, right? Here’s each bit with explanations.

Numbers our text file.
sed = /home/user/todo/todo.txt | sed ‘N;s/n/ /’

Textwraps our text file at 80 characters
fold

Strips trailing whitespace
sed -e ‘s/[ t]*$//’

Indents properly so that when a line is wrapped, it’s all nice and pretty
sed -e ‘/^[0-9]/!s/[ t]*/ /’

Pads the line to 80 characters with sed.
sed -e :a -e ‘s/^.{1,80}$/& /;ta’

Columnize it
column -c 200

So here it is as part of a conky rc file. Note the MUCH larger text buffer size:

text_buffer_size 8128
uppercase no
color1 F8DF58
update_interval 10
update_interval_on_battery 10
TEXT
${color DarkSlateGray}${hr 2}
${color White}${execi 30 sed = /home/user/todo/todo.txt | sed ‘N;s/n/ /’ | fold |sed -e ‘s/[ t]$//’ | sed -e ‘/^[0-9]/!s/[ t]/ /’| sed -e :a -e ‘s/^.{1,80}$/& /;ta’|column -c 200}
${color DarkSlateGray}${hr 2}