You are not logged in.

#1 2009-07-16 16:04:04

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Another todo script

This one is even simpler than Ghost's wink

As in, less functional, but it does what I need it to do tongue

#!/bin/zsh

flag=$1
arg=$2
todofile="/home/barrucadu/docs/main.todo"

function append()
{
    echo "* TODO $arg" >> $todofile
}

function delete()
{
    sed -i "$arg d" $todofile
}

function toggle()
{
    sed -i "$arg s/^\* TODO/\* ODOT/" $todofile
    sed -i "$arg s/^\* DONE/\* ENODE/" $todofile
    sed -i "$arg s/^\* ENODE/\* TODO/" $todofile
    sed -i "$arg s/^\* ODOT/\* DONE/" $todofile
}

function clean()
{
    sed -i "/^\* DONE .*$/d" $todofile
}

function listall()
{
    grep -n -e "^\* \(TODO\|DONE\)" $todofile
}

function listtodo()
{
    grep -n "^\* TODO" $todofile
}

function listfinished()
{
    grep -n "^\* DONE" $todofile
}

function help()
{
    echo "Usage: todo [flag] [arg]"
    echo
    echo "---"
    echo
    echo "A simple todo-file manager, which manipulates todo files in a subset of the Emacs Org-mode format."
    echo
    echo "---"
    echo
    echo "Flags:"
    echo "    a  - Append new entry."
    echo "         arg = Description"
    echo
    echo "    d  - Delete existing entry."
    echo "         arg = Line number"
    echo
    echo "    t  - Toggle an entry's todo/done state.."
    echo "         arg = Line number"
    echo
    echo "    c  - Clean finished entries from list."
    echo "    l  - List entries."
    echo "    lt - List entries marked as to do."
    echo "    lf - List entries marked as finished."
    echo "    h  - Display this text."
    echo
}

case "$flag" in
    "a")
        append
        ;;
    "d")
        delete
        ;;
    "t")
        toggle
        ;;
    "c")
        clean
        ;;
    "l")
        listall
        ;;
    "lt")
        listtodo
        ;;
    "lf")
        listfinished
        ;;
    "h")
        help
        ;;
    "")
        help
        ;;
    *)
        echo "Error: unknown flag '$flag'."
        return 1
        ;;
esac

return 0

It's a simple little script, running with no args will give you a help message. You'll probably want to edit the $todofile variable to point to your todo file. Also, you can do cool things like this:

todo lt | sed "s/^.* TODO /To Do: /" | sort -R | head -n1

Which I've added to my .zshrc, so now, upon opening a terminal, I see a random thing I have yet to do. Hopefully this will spur me to action.

As you can probably tell from the name of my todo file (main.todo), I've considered support for multiple todo lists. But I've decided that if I do that, it'll be in one file, but using org-mode tags to separate the lists. I don't think I'll add the feature for a while (if ever) though.

Offline

#2 2009-07-16 16:33:20

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Another todo script

HEY!  We should start a todo-off, like the infamous 'arch is best' thread.

I've got an even simpler one in my zshrc wink

todo()
{
  if [ -z $1 ]; then
    cat $HOME/.todo
    return
  fi

  case $1 in
    "add")
      echo $2 >> $HOME/.todo
    ;;
    "del")
      todo=$(< $HOME/.todo | sed 's/'$2'//;tx;p;:x;d')
      echo $todo > $HOME/.todo
    ;;
  esac
}

Yet even LESS functional.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#3 2009-07-16 16:43:29

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Another todo script

Well, yours does support deleting things by entering the todo text, which mine doesn't. So it could be considered more functional in that way tongue

Offline

#4 2009-07-16 17:15:51

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Another todo script

Ok, so it's not as simple, but it's still cli and pretty powerful for how small it is....the todo.txt script written by one of the Lifehacker.com editors. Works great and is pretty hackable if you so desire....

Scott

Offline

#5 2009-07-26 11:49:44

rich_o
Member
Registered: 2008-07-28
Posts: 49

Re: Another todo script

Hey,

really liked that rson451's simple todo thingy. But deleting entries is kinda sketchy. And i like my entries numbered. And i like to delete my entries by that number instead of relying on some regex. So here's my version:

todo()
{
  if [ -z $1 ]; then
    awk '{ i += 1; print i": "$0 }' $HOME/.todo
    return
  fi

  case $1 in
    "add")
      echo $2 >> $HOME/.todo
    ;;
    "del")
      todo=$(< $HOME/.todo | sed "$2"'d')
      rm $HOME/.todo  # i needed that, because it didn't wanted to echo into an existing file.
      echo $todo > $HOME/.todo
    ;;
    "search")
      grep -ni --color=never $2 $HOME/.todo | sed -e 's/:/: /'
    ;;
  esac
}

Edit: added simple search function

Last edited by rich_o (2009-07-26 14:32:31)

Offline

#6 2009-07-26 12:26:05

jordz
Member
Registered: 2006-02-01
Posts: 248

Re: Another todo script

firecat53 wrote:

Ok, so it's not as simple, but it's still cli and pretty powerful for how small it is....the todo.txt script written by one of the Lifehacker.com editors. Works great and is pretty hackable if you so desire....

Scott

That script looks great, thanks smile

Edit: It's even in AUR smile

Last edited by jordz (2009-07-26 12:27:41)

Offline

#7 2009-07-26 13:11:05

jelly
Administrator
From: /dev/null
Registered: 2008-06-10
Posts: 714

Re: Another todo script

jordz wrote:
firecat53 wrote:

Ok, so it's not as simple, but it's still cli and pretty powerful for how small it is....the todo.txt script written by one of the Lifehacker.com editors. Works great and is pretty hackable if you so desire....

Scott

That script looks great, thanks smile

Edit: It's even in AUR smile

Homemade is way cooler ! I made one in haskell a time ago , it also supports searching. But i am thinking of rewriting it and writing one in python tongue

What would be more cooler is to have the todolist editor talk with your server / a website so you can access it from the whole word wink

Last edited by jelly (2009-07-26 13:18:45)

Offline

Board footer

Powered by FluxBB