#!/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 " else todo_list fi