You are not logged in.

#1 2011-08-17 09:53:46

dpx3001
Member
Registered: 2011-08-17
Posts: 3

todox - Taskpaper based to-do reminder

Taskpaper is nice, lightweight and very flexible to-do list format, looks something like this:

# done,cancelled,now,urgent,today,soon,later,followup

Example Project:
        - Start example project file @computer @done
        - Brainstorm project with colleagues @now
        - Email Joan about project @today
        Sub Project:
                - Sub task @later

Next Project:
        - Draft ideas for next project @urgent @today
        - Email Bob to arrange meeting @followup

Projects end with ':'. You can have any number of sub-projects. Each to-do item starts with '- '. You can add any number of tags at the end of each item. All tags start with '@'.

There is also vim script that helps editing taskpaper document. You can find it here: http://www.vim.org/scripts/script.php?script_id=2027

Todox will parse existing taskpaper document and display results in very readable format:

#!/usr/bin/ruby
CLR_BLACK = "\e[1;30m"    #Black
CLR_RED = "\e[1;31m"        #Red
CLR_GREEN = "\e[1;32m"    #Green
CLR_YELLOW = "\e[1;33m"    #Yellow
CLR_BLUE = "\e[1;34m"        #Blue
CLR_MAGENTA = "\e[1;35m"    #Magenta
CLR_CYAN = "\e[1;36m"        #Cyan
CLR_WHITE = "\e[1;37m"    #White
CLR_DEFAULT = ""
CLR_CLEAR = "\e[0m";
DONE_TAG = "@done"

TODO_TO_USE = "todo.taskpaper" 

def outtext (txt,clr)
    if (clr == "") then
        puts txt
    else
        puts clr+txt+CLR_CLEAR
    end
end

def list_tag (tagtitle,tagname,clr,clrtitle,showall)
    project = "???"
    titleshown = false
    File.open(TODO_TO_USE, "r") do |infile| 
        while (line = infile.gets) 
            line = line.gsub(/- /,"")
            # if it is project name line take project name
            if (/#*:/.match line) then
                project = line
            end
            # if done then skip
            if (line.include? DONE_TAG) then
                next
            end
            # if tag matches
            if (line.include? tagname) then
                if not titleshown then
                    if not (tagtitle=="") then
                        outtext(tagtitle,clrtitle)
                        puts ""
                        titleshown = true
                    end
                end
                if (showall == true) then
                    if (line.include? "@urgent") then
                        outtext("    "+project.strip+" "+line.strip,CLR_RED)
                    else
                        outtext("    "+project.strip+" "+line.strip,clr)
                    end
                else
                    outtext("*** "+project.strip.upcase+" "+line.strip.gsub(/ @now/,"").upcase+" ***   ","")
                    exit
                end
	    end
        end
        infile.close
    end
    if titleshown then
        puts ""
    end
end

if (ARGV.length == 0) then
    list_tag("@NOW","@now",CLR_YELLOW,CLR_WHITE,true)
    list_tag("@TODAY","@today",CLR_DEFAULT,CLR_WHITE,true)
    list_tag("@SOON","@soon",CLR_BLACK,CLR_WHITE,true)
    list_tag("@LATER","@later",CLR_BLACK,CLR_WHITE,true)
    list_tag("@FOLLOWUP","@followup",CLR_BLACK,CLR_BLACK,true)
    exit
end

list_tag("","@now","","",false)
outtext("*** NOTHING TO DO? ***   ","")

Just save sample taskpaper document and todox.rb anywhere, set TODO_TO_USE path to point to todo.taskpaper and start todox.rb.
There are two modes: If called with any parameter, todox will display ONE line that contains @now tag -- I am using that to display task at hand in conky (actually in dwm bar using conky). If called without parameters todox will display all tags listed at the end of todox.rb (easy to find and edit). I am using no parameters call to display entire to-do (all tags I care about anyway) any time I start terminal (called from .bashrc or .zshrc).

So start hacking and enjoy :) If you do something useful please share code.

Taskpaper format sample:
http://pastebin.com/ErMwCgEx

Todox.rb:
http://pastebin.com/RnWvx6Uf

Offline

#2 2011-08-18 01:51:31

saline
Member
Registered: 2010-02-20
Posts: 86

Re: todox - Taskpaper based to-do reminder

I made some minor changes. Now it prints the next task by default and everything if "all" is the only argument.  I might do some more later.

#!/usr/bin/ruby -w
# encoding: utf-8

DONE_TAG = "@done"
TODO_TO_USE = "todo.taskpaper" 

class String
  COLORS = { black: "\e[1;30m", red: "\e[1;31m", green: "\e[1;32m",
    yellow: "\e[1;33m", blue: "\e[1;34m", magenta: "\e[1;35m", cyan: "\e[1;36m",
    white: "\e[1;37m", default: "", clear: "\e[0m"}

  def color(color=:default)
    COLORS[color] + self + COLORS[:clear]
  end
end

def list_tag(tagtitle, tagname, color, titlecolor, showall=true)
  project = "???"
  titleshown = false
  File.open(TODO_TO_USE, "r") do |infile| 
    while line = infile.gets
      line = line.gsub(/- /,"")
      
      # if it is project name line take project name
      project = line if /#*:/.match line
      
      # if done then skip
      next if line.include? DONE_TAG

      # if tag matches
      if line.include? tagname then
        if not titleshown then
          puts tagtitle.color titlecolor if tagtitle != ""
          titleshown = true
        end
  
        if showall then
          puts "    #{project.strip} #{line.strip}".color((line.include? "@urgent") ? :red : color)
        else
          puts "*** #{project.strip.upcase} #{line.strip.gsub(/ @now/,"").upcase} ***   "
          exit
        end
      end
    end
    infile.close
  end

  if titleshown then
    puts ""
  end
end

if ARGV.length == 1 && ARGV[0] == "all" then
  list_tag "@NOW", "@now", :yellow, :white
  list_tag "@TODAY", "@today", :default, :white
  list_tag "@SOON", "@soon", :black, :white
  list_tag "@LATER", "@later", :black, :white
  list_tag "@FOLLOWUP", "@followup", :black, :black
  exit
end

list_tag "", "@now", :default, :default, false
puts "*** NOTHING TO DO? ***   "

Offline

Board footer

Powered by FluxBB