aboutsummaryrefslogtreecommitdiff
path: root/todo
blob: ba9127fa4db766d2838bd31b5f5f3fcdd0d38ad2 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/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
    if [ ! -d "$folder" ]; then
      continue
    fi

    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 {
  local status="$1"

  # User's Taskwarrior
  if which task &> /dev/null; then
    if [ "`task status:pending count 2> /dev/null`" != "0" ]; then
      echo "taskwarrior:"
      #echo ""
      task list 2> /dev/null
      echo ""
    fi

    # Taskwarrior data from projects
    if [ ! -z "$status" ]; then
      taskstatus="+$status"
      SILENT="true"
    fi

    SILENT=$SILENT tasks $taskstatus list 2> /dev/null
    echo ""
  fi

  # User's Timewarrior
  if which timew &> /dev/null; then
    if ! timew | grep -q "^There is no active time tracking."; then
      timew
      echo ""
    fi
  fi

  todo_find | while read todo; do
    if [ "$todo" != "$NAME" ]; then
      if [ ! -z "$status" ] && ! grep -q "\($status\)" $todo; then
        continue
      fi

      path="`echo $todo | sed -e "s|^$HOME|~|"`"
      delim="===`echo $path | sed -e 's|.|=|g'`"
      #echo ""
      echo In $path
      echo $delim
      echo ""

      if [ ! -z "$status" ]; then
        grep -e '* [ ]' -e '-' $todo | grep "\($status\)"
      else
        grep -e '* [ ]' -e '-' $todo
      fi

      echo ""
    fi
  done
}

if [ "$OPTION" == "find" ]; then
  todo_find | grep -v -e "^$NAME$" | sed -e "s|^$HOME|~|"
elif [ "$OPTION" == "count" ]; then
  todo_find | grep -v $NAME | wc -l
elif [ "$OPTION" == "show" ] || [ "$OPTION" == "see" ] || [ "$OPTION" == "view" ]; then
  if [ ! -z "$2" ] && [ -e "$2" ]; then
    # Check TODO inside files
    grep -i "todo" $2 | sed -e 's/^  *//'

    # Check also for FIXMEs
    fixmes $2
  elif cd $2 &> /dev/null; then
    (
    cd $2 &> /dev/null
    find -maxdepth 1 -xtype f -iname 'todo*' -exec cat {} \; | grep -e '*' -e '-'
    )
  fi
elif [ "$OPTION" == "list" ]; then
  todo_list $2
elif [ "$OPTION" == "help" ]; then
  echo "usage: $BASENAME [list|count]"
  echo "       $BASENAME <show|see|view> <file|project>"
else
  todo_list
fi