aboutsummaryrefslogtreecommitdiff
path: root/todo
blob: 9c62f3267d0093f28d7e5e0e41c8349c6be37bc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#
# Task list visualizer.
#

# Basic params
CONFIG="$HOME/.config/todo"
NAME="$0"
BASENAME="`basename $NAME`"
OPTION="$1"

# Config
if [ -e "$CONFIG" ] ; then
  source $CONFIG
fi

# Custom params
TODO_MAXDEPTH="2"
WORKPATH="${WORKPATH:=~/}"
FOLDERS="`echo $WORKPATH | tr ':' ' ' | sed -e "s|~|$HOME|g"`"

# Iterate
function todo_find {
  for folder in $FOLDERS; do
    find $folder/ -maxdepth $TODO_MAXDEPTH -xtype f -iname 'todo*' | while read todo; do
      # Ignore lists without tasks
      if grep -q -e '*' -e '-' $todo; then
        echo $todo
      fi
    done
  done
}

function todo_list {
  todo_find | while read todo; do
    if [ "$todo" != "$NAME" ]; then
     path="`echo $todo | sed -e "s|^$HOME|~|"`"
     delim="===`echo $path | sed -e 's|.|=|g'`"
     echo ""
     echo In $path
     echo $delim
     echo ""
     grep -e '*' -e '-' $todo
    fi
  done
}

if [ "$OPTION" == "list" ]; then
  todo_find | grep -v -e "^$NAME$" | sed -e "s|^$HOME|~|"
elif [ "$OPTION" == "count" ]; then
  todo_find | grep -v $NAME | wc -l
elif [ "$OPTION" == "see" ]; then
  if [ ! -z "$2" ] && [ -e "$2" ]; then
    grep "TODO" $2 | sed -e 's/^  *//'
  fi
elif [ "$OPTION" == "help" ]; then
  echo "usage: $BASENAME [list|count]"
  echo "       $BASENAME see <file>"
else
  todo_list
fi