Cleaning indentation and mix of tabs/spaces, nothing else I swear ;-)

Signed-off-by: ginatrapani <ginatrapani@gmail.com>
This commit is contained in:
Philippe Teuwen
2009-03-07 04:16:13 +08:00
committed by ginatrapani
parent 25c6505007
commit 586abe8282
2 changed files with 399 additions and 435 deletions

762
todo.sh
View File

@@ -57,7 +57,7 @@ help()
depri NUMBER depri NUMBER
dp NUMBER dp NUMBER
Deprioritizes (removes the priority) from the item Deprioritizes (removes the priority) from the item
on line NUMBER in todo.txt. on line NUMBER in todo.txt.
do NUMBER do NUMBER
Marks item on line NUMBER as done in todo.txt. Marks item on line NUMBER as done in todo.txt.
@@ -97,7 +97,7 @@ help()
Moves a line from source text file (SRC) to destination text file (DEST). Moves a line from source text file (SRC) to destination text file (DEST).
Both source and destination file must be located in the directory defined Both source and destination file must be located in the directory defined
in the configuration directory. When SRC is not defined in the configuration directory. When SRC is not defined
it's by default todo.txt. it's by default todo.txt.
prepend NUMBER "TEXT TO PREPEND" prepend NUMBER "TEXT TO PREPEND"
prep NUMBER "TEXT TO PREPEND" prep NUMBER "TEXT TO PREPEND"
@@ -134,7 +134,7 @@ help()
on task deletion on task deletion
-t -t
Prepend the current date to a task automatically Prepend the current date to a task automatically
when it's added. when it's added.
-v -v
Verbose mode turns on confirmation messages Verbose mode turns on confirmation messages
-V -V
@@ -143,15 +143,15 @@ EndHelp
if [ -d "$HOME/.todo.actions.d" ] if [ -d "$HOME/.todo.actions.d" ]
then then
echo "" echo ""
for action in $HOME/.todo.actions.d/* for action in $HOME/.todo.actions.d/*
do do
if [ -x $action ] if [ -x $action ]
then then
$action usage $action usage
fi fi
done done
echo "" echo ""
fi fi
@@ -172,16 +172,16 @@ cleanup()
archive() archive()
{ {
#defragment blank lines #defragment blank lines
sed -i.bak -e '/./!d' "$TODO_FILE" sed -i.bak -e '/./!d' "$TODO_FILE"
[[ $VERBOSE = 1 ]] && grep "^x " "$TODO_FILE" [[ $VERBOSE = 1 ]] && grep "^x " "$TODO_FILE"
grep "^x " "$TODO_FILE" >> "$DONE_FILE" grep "^x " "$TODO_FILE" >> "$DONE_FILE"
sed -i.bak '/^x /d' "$TODO_FILE" sed -i.bak '/^x /d' "$TODO_FILE"
cp "$TODO_FILE" "$TMP_FILE" cp "$TODO_FILE" "$TMP_FILE"
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE" sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P' "$TMP_FILE" > "$TODO_FILE"
#[[ $VERBOSE = 1 ]] && echo "TODO: Duplicate tasks have been removed." #[[ $VERBOSE = 1 ]] && echo "TODO: Duplicate tasks have been removed."
[[ $VERBOSE = 1 ]] && echo "TODO: $TODO_FILE archived." [[ $VERBOSE = 1 ]] && echo "TODO: $TODO_FILE archived."
cleanup cleanup
} }
@@ -199,32 +199,32 @@ while getopts ":fhpnatvVd:" Option
do do
case $Option in case $Option in
a ) a )
AUTO_ARCHIVE=0 AUTO_ARCHIVE=0
;; ;;
d ) d )
CFG_FILE=$OPTARG CFG_FILE=$OPTARG
;; ;;
f ) f )
FORCE=1 FORCE=1
;; ;;
h ) h )
help help
;; ;;
n ) n )
PRESERVE_LINE_NUMBERS=0 PRESERVE_LINE_NUMBERS=0
;; ;;
p ) p )
PLAIN=1 PLAIN=1
;; ;;
t ) t )
DATE_ON_ADD=1 DATE_ON_ADD=1
;; ;;
v ) v )
VERBOSE=1 VERBOSE=1
;; ;;
V ) V )
version version
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
@@ -234,7 +234,7 @@ shift $(($OPTIND - 1))
if [ -e "$CFG_FILE_ALT" ] if [ -e "$CFG_FILE_ALT" ]
then then
CFG_FILE="$CFG_FILE_ALT" CFG_FILE="$CFG_FILE_ALT"
fi fi
} }
@@ -252,13 +252,12 @@ echo '' > "$TMP_FILE" || die "Fatal Error: Unable to write in $TODO_DIR"
[ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE" [ -f "$DONE_FILE" ] || cp /dev/null "$DONE_FILE"
[ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE" [ -f "$REPORT_FILE" ] || cp /dev/null "$REPORT_FILE"
if [ $PLAIN = 1 ]; then if [ $PLAIN = 1 ]; then
PRI_A=$NONE PRI_A=$NONE
PRI_B=$NONE PRI_B=$NONE
PRI_C=$NONE PRI_C=$NONE
PRI_X=$NONE PRI_X=$NONE
DEFAULT=$NONE DEFAULT=$NONE
fi fi
# === HEAVY LIFTING === # === HEAVY LIFTING ===
@@ -269,438 +268,403 @@ action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' )
case $action in case $action in
"add" | "a") "add" | "a")
if [[ -z "$2" && $FORCE = 0 ]]; then if [[ -z "$2" && $FORCE = 0 ]]; then
echo -n "Add: " echo -n "Add: "
read input read input
else else
[ -z "$2" ] && die "usage: $0 add \"TODO ITEM\"" [ -z "$2" ] && die "usage: $0 add \"TODO ITEM\""
shift shift
input=$* input=$*
fi fi
if [[ $DATE_ON_ADD = 1 ]]; then
if [[ $DATE_ON_ADD = 1 ]]; then now=`date '+%Y-%m-%d'`
now=`date '+%Y-%m-%d'` input="$now $input"
input="$now $input" fi
fi echo "$input" >> "$TODO_FILE"
TASKNUM=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
echo "$input" >> "$TODO_FILE" [[ $VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;;
TASKNUM=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
[[ $VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;;
"addto" ) "addto" )
[ -z "$2" ] && die "usage: $0 addto DEST \"TODO ITEM\"" [ -z "$2" ] && die "usage: $0 addto DEST \"TODO ITEM\""
dest="$TODO_DIR/$2" dest="$TODO_DIR/$2"
[ -z "$3" ] && die "usage: $0 addto DEST \"TODO ITEM\""
shift
shift
input=$*
[ -z "$3" ] && die "usage: $0 addto DEST \"TODO ITEM\"" if [ -f "$dest" ]; then
shift echo "$input" >> "$dest"
shift TASKNUM=$(wc -l "$dest" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
input=$* [[ $VERBOSE = 1 ]] && echo "TODO: '$input' added to $dest on line $TASKNUM."
else
if [ -f "$dest" ]; then echo "TODO: Destination file $dest does not exist."
fi
echo "$input" >> "$dest" cleanup;;
TASKNUM=$(wc -l "$dest" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
[[ $VERBOSE = 1 ]] && echo "TODO: '$input' added to $dest on line $TASKNUM."
else
echo "TODO: Destination file $dest does not exist."
fi
cleanup;;
"append" | "app" ) "append" | "app" )
errmsg="usage: $0 append ITEM# \"TEXT TO APPEND\"" errmsg="usage: $0 append ITEM# \"TEXT TO APPEND\""
shift; item=$1; shift shift; item=$1; shift
[ -z "$item" ] && die "$errmsg" [ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE")
todo=$(sed "$item!d" "$TODO_FILE") [ -z "$todo" ] && die "$item: No such todo."
[ -z "$todo" ] && die "$item: No such todo." if [[ -z "$1" && $FORCE = 0 ]]; then
echo -n "Append: "
read input
if [[ -z "$1" && $FORCE = 0 ]]; then else
echo -n "Append: " input=$*
read input fi
else if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
input=$* newtodo=$(sed "$item!d" "$TODO_FILE")
fi [[ $VERBOSE = 1 ]] && echo "$item: $newtodo"
else
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then echo "TODO: Error appending task $item."
newtodo=$(sed "$item!d" "$TODO_FILE") fi
[[ $VERBOSE = 1 ]] && echo "$item: $newtodo" cleanup;;
else
echo "TODO: Error appending task $item."
fi
cleanup;;
"archive" ) "archive" )
archive;; archive;;
"del" | "rm" ) "del" | "rm" )
# replace deleted line with a blank line when PRESERVE_LINE_NUMBERS is 1 # replace deleted line with a blank line when PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $0 del ITEM#" errmsg="usage: $0 del ITEM#"
item=$2 item=$2
[ -z "$item" ] && die "$errmsg" [ -z "$item" ] && die "$errmsg"
if [ -z "$3" ]; then if [ -z "$3" ]; then
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
if sed -ne "$item p" "$TODO_FILE" | grep "^."; then if sed -ne "$item p" "$TODO_FILE" | grep "^."; then
DELETEME=$(sed "$2!d" "$TODO_FILE") DELETEME=$(sed "$2!d" "$TODO_FILE")
if [ $FORCE = 0 ]; then if [ $FORCE = 0 ]; then
echo "Delete '$DELETEME'? (y/n)" echo "Delete '$DELETEME'? (y/n)"
read ANSWER read ANSWER
else else
ANSWER="y" ANSWER="y"
fi fi
if [ "$ANSWER" = "y" ]; then
if [ "$ANSWER" = "y" ]; then if [ $PRESERVE_LINE_NUMBERS = 0 ]; then
if [ $PRESERVE_LINE_NUMBERS = 0 ]; then # delete line (changes line numbers)
# delete line (changes line numbers) sed -i.bak -e $2"s/^.*//" -e '/./!d' "$TODO_FILE"
sed -i.bak -e $2"s/^.*//" -e '/./!d' "$TODO_FILE" else
else # leave blank line behind (preserves line numbers)
# leave blank line behind (preserves line numbers) sed -i.bak -e $2"s/^.*//" "$TODO_FILE"
sed -i.bak -e $2"s/^.*//" "$TODO_FILE" fi
fi [[ $VERBOSE = 1 ]] && echo "TODO: '$DELETEME' deleted."
[[ $VERBOSE = 1 ]] && echo "TODO: '$DELETEME' deleted." cleanup
cleanup else
echo "TODO: No tasks were deleted."
else fi
echo "TODO: No tasks were deleted." else
fi echo "$item: No such todo."
else fi
echo "$item: No such todo."
fi
else else
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE" sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
[[ $VERBOSE = 1 ]] && echo "TODO: $3 removed from $item." [[ $VERBOSE = 1 ]] && echo "TODO: $3 removed from $item."
fi ;; fi ;;
"depri" | "dp" ) "depri" | "dp" )
item=$2 item=$2
errmsg="usage: $0 depri ITEM#" errmsg="usage: $0 depri ITEM#"
todo=$(sed "$item!d" "$TODO_FILE") todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo." [ -z "$todo" ] && die "$item: No such todo."
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
sed -e $item"s/^(.*) //" "$TODO_FILE" > /dev/null 2>&1 sed -e $item"s/^(.*) //" "$TODO_FILE" > /dev/null 2>&1
if [ "$?" -eq 0 ]; then if [ "$?" -eq 0 ]; then
#it's all good, continue #it's all good, continue
sed -i.bak -e $2"s/^(.*) //" "$TODO_FILE" sed -i.bak -e $2"s/^(.*) //" "$TODO_FILE"
NEWTODO=$(sed "$2!d" "$TODO_FILE") NEWTODO=$(sed "$2!d" "$TODO_FILE")
[[ $VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`" [[ $VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`"
[[ $VERBOSE = 1 ]] && echo "TODO: $item deprioritized." [[ $VERBOSE = 1 ]] && echo "TODO: $item deprioritized."
cleanup cleanup
else else
die "$errmsg" die "$errmsg"
fi;; fi;;
"do" ) "do" )
errmsg="usage: $0 do ITEM#" errmsg="usage: $0 do ITEM#"
item=$2 item=$2
[ -z "$item" ] && die "$errmsg" [ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE") todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo." [ -z "$todo" ] && die "$item: No such todo."
now=`date '+%Y-%m-%d'` now=`date '+%Y-%m-%d'`
# remove priority once item is done # remove priority once item is done
sed -i.bak $item"s/^(.*) //" "$TODO_FILE" sed -i.bak $item"s/^(.*) //" "$TODO_FILE"
sed -i.bak $item"s|^|&x $now |" "$TODO_FILE" sed -i.bak $item"s|^|&x $now |" "$TODO_FILE"
newtodo=$(sed "$item!d" "$TODO_FILE") newtodo=$(sed "$item!d" "$TODO_FILE")
[[ $VERBOSE = 1 ]] && echo "$item: $newtodo" [[ $VERBOSE = 1 ]] && echo "$item: $newtodo"
[[ $VERBOSE = 1 ]] && echo "TODO: $item marked as done." [[ $VERBOSE = 1 ]] && echo "TODO: $item marked as done."
if [ $AUTO_ARCHIVE = 1 ]; then if [ $AUTO_ARCHIVE = 1 ]; then
archive archive
fi fi
cleanup ;;
cleanup ;;
"list" | "ls" ) "list" | "ls" )
item=$2 item=$2
if [ -z "$item" ]; then if [ -z "$item" ]; then
echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`" echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`"
echo "--" echo "--"
NUMTASKS=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') NUMTASKS=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
echo "TODO: $NUMTASKS tasks in $TODO_FILE." echo "TODO: $NUMTASKS tasks in $TODO_FILE."
else else
command=`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/' | grep -i $item ` command=`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/' | grep -i $item `
shift shift
shift shift
for i in $* for i in $*
do do
command=`echo "$command" | grep -i $i ` command=`echo "$command" | grep -i $i `
done done
command=`echo "$command" | sort -f -k2` command=`echo "$command" | sort -f -k2`
echo -e "$command"
echo -e "$command" fi
fi cleanup ;;
cleanup ;;
"listall" | "lsa" ) "listall" | "lsa" )
item=$2 item=$2
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE" cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
if [ -z "$item" ]; then if [ -z "$item" ]; then
echo -e "`sed = "$TMP_FILE" | sed 'N; s/^/ /; s/ *\(.\{3,\}\)\n/\1 /' | sed 's/^ /00/' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`" echo -e "`sed = "$TMP_FILE" | sed 'N; s/^/ /; s/ *\(.\{3,\}\)\n/\1 /' | sed 's/^ /00/' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`"
else else
command=`sed = "$TMP_FILE" | sed 'N; s/^/ /; s/ *\(.\{3,\}\)\n/\1 /' | sed 's/^ /00/' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/' | grep -i $item ` command=`sed = "$TMP_FILE" | sed 'N; s/^/ /; s/ *\(.\{3,\}\)\n/\1 /' | sed 's/^ /00/' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/' | grep -i $item `
shift shift
shift shift
for i in $* for i in $*
do do
command=`echo "$command" | grep -i $i ` command=`echo "$command" | grep -i $i `
done done
command=`echo "$command" | sort -f -k2` command=`echo "$command" | sort -f -k2`
echo -e "$command"
echo -e "$command" fi
fi cleanup ;;
cleanup ;;
"listfile" | "lf" ) "listfile" | "lf" )
src="$TODO_DIR/$2" src="$TODO_DIR/$2"
if [ -z "$3" ]; then if [ -z "$3" ]; then
item="" item=""
else else
item=$3 item=$3
fi fi
if [ -f "$src" ]; then
if [ -f "$src" ]; then if [ -z "$item" ]; then
if [ -z "$item" ]; then echo -e "`sed = "$src" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`"
echo -e "`sed = "$src" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`" if [ $VERBOSE = 1 ]; then
if [ $VERBOSE = 1 ]; then echo "--"
echo "--" NUMTASKS=$( sed '/./!d' "$src" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
NUMTASKS=$( sed '/./!d' "$src" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') echo "TODO: $NUMTASKS lines in $src."
echo "TODO: $NUMTASKS lines in $src." fi
fi else
else command=`sed = "$src" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/' | grep -i $item `
command=`sed = "$src" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/' | grep -i $item ` shift
shift shift
shift for i in $*
for i in $* do
do command=`echo "$command" | grep -i $i `
command=`echo "$command" | grep -i $i ` done
done command=`echo "$command" | sort -f -k2`
command=`echo "$command" | sort -f -k2` echo -e "$command"
fi
echo -e "$command" else
fi echo "TODO: File $src does not exist."
else fi
echo "TODO: File $src does not exist." cleanup ;;
fi
cleanup ;;
"listcon" | "lsc" ) "listcon" | "lsc" )
gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '@' | sort | uniq gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '@' | sort | uniq
cleanup ;; cleanup ;;
"listproj" | "lsprj" ) "listproj" | "lsprj" )
gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '+' | sort | uniq gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '+' | sort | uniq
cleanup ;; cleanup ;;
"listpri" | "lsp" ) "listpri" | "lsp" )
pri=$( printf "%s\n" "$2" | tr 'a-z' 'A-Z' ) pri=$( printf "%s\n" "$2" | tr 'a-z' 'A-Z' )
errmsg="usage: $0 listpri PRIORITY
errmsg="usage: $0 listpri PRIORITY
note: PRIORITY must a single letter from A to Z." note: PRIORITY must a single letter from A to Z."
if [ -z "$pri" ]; then if [ -z "$pri" ]; then
echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`" | grep \([A-Z]\) echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`" | grep \([A-Z]\)
if [ $VERBOSE = 1 ]; then if [ $VERBOSE = 1 ]; then
echo "--" echo "--"
NUMTASKS=$(grep \([A-Z]\) "$TODO_FILE" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') NUMTASKS=$(grep \([A-Z]\) "$TODO_FILE" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
echo "TODO: $NUMTASKS prioritized tasks in $TODO_FILE." echo "TODO: $NUMTASKS prioritized tasks in $TODO_FILE."
fi fi
else else
[[ "$pri" = +([A-Z]) ]] || die "$errmsg" [[ "$pri" = +([A-Z]) ]] || die "$errmsg"
echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`" | grep \($pri\) echo -e "`sed = "$TODO_FILE" | sed 'N; s/^/ /; s/ *\(.\{2,\}\)\n/\1 /' | sed 's/^ /0/' | sort -f -k2 | sed 's/^ /0/' | sort -f -k2 | sed '/^[0-9][0-9] x /!s/\(.*(A).*\)/'$PRI_A'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(B).*\)/'$PRI_B'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*(C).*\)/'$PRI_C'\1'$DEFAULT'/g' | sed '/^[0-9][0-9] x /!s/\(.*([A-Z]).*\)/'$PRI_X'\1'$DEFAULT'/'`" | grep \($pri\)
if [ $VERBOSE = 1 ]; then if [ $VERBOSE = 1 ]; then
echo "--" echo "--"
NUMTASKS=$(grep \($pri\) "$TODO_FILE" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') NUMTASKS=$(grep \($pri\) "$TODO_FILE" | wc -l | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
echo "TODO: $NUMTASKS tasks prioritized $pri in $TODO_FILE." echo "TODO: $NUMTASKS tasks prioritized $pri in $TODO_FILE."
fi fi
fi
fi cleanup;;
cleanup;;
"move" | "mv" ) "move" | "mv" )
# replace moved line with a blank line when PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $0 mv ITEM# DEST [SRC]"
item=$2
dest="$TODO_DIR/$3"
src="$TODO_DIR/$4"
# replace moved line with a blank line when PRESERVE_LINE_NUMBERS is 1 [ -z "$item" ] && die "$errmsg"
errmsg="usage: $0 mv ITEM# DEST [SRC]" [ -z "$4" ] && src="$TODO_FILE"
[ -z "$dest" ] && die "$errmsg"
item=$2 [[ "$item" = +([0-9]) ]] || die "$errmsg"
dest="$TODO_DIR/$3"
src="$TODO_DIR/$4" if [ -f "$src" ]; then
if [ -f "$dest" ]; then
if sed -ne "$item p" "$src" | grep "^."; then
MOVEME=$(sed "$item!d" "$src")
if [ $FORCE = 0 ]; then
echo "Move '$MOVEME' from $src to $dest? (y/n)"
read ANSWER
else
ANSWER="y"
fi
if [ "$ANSWER" = "y" ]; then
if [ $PRESERVE_LINE_NUMBERS = 0 ]; then
# delete line (changes line numbers)
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$src"
else
# leave blank line behind (preserves line numbers)
sed -i.bak -e $item"s/^.*//" "$src"
fi
echo "$MOVEME" >> "$dest"
[ -z "$item" ] && die "$errmsg" [[ $VERBOSE = 1 ]] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
cleanup
[ -z "$4" ] && src="$TODO_FILE" else
[ -z "$dest" ] && die "$errmsg" echo "TODO: No tasks moved."
fi
[[ "$item" = +([0-9]) ]] || die "$errmsg" else
echo "$item: No such item in $src."
if [ -f "$src" ]; then fi
if [ -f "$dest" ]; then else
echo "TODO: Destination file $dest does not exist."
if sed -ne "$item p" "$src" | grep "^."; then fi
MOVEME=$(sed "$item!d" "$src") else
echo "TODO: Source file $src does not exist."
if [ $FORCE = 0 ]; then fi
echo "Move '$MOVEME' from $src to $dest? (y/n)" cleanup;;
read ANSWER
else
ANSWER="y"
fi
if [ "$ANSWER" = "y" ]; then
if [ $PRESERVE_LINE_NUMBERS = 0 ]; then
# delete line (changes line numbers)
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$src"
else
# leave blank line behind (preserves line numbers)
sed -i.bak -e $item"s/^.*//" "$src"
fi
echo "$MOVEME" >> "$dest"
[[ $VERBOSE = 1 ]] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
cleanup
else
echo "TODO: No tasks moved."
fi
else
echo "$item: No such item in $src."
fi
else
echo "TODO: Destination file $dest does not exist."
fi
else
echo "TODO: Source file $src does not exist."
fi
cleanup;;
"prepend" | "prep" ) "prepend" | "prep" )
errmsg="usage: $0 prepend ITEM# \"TEXT TO PREPEND\"" errmsg="usage: $0 prepend ITEM# \"TEXT TO PREPEND\""
shift; item=$1; shift shift; item=$1; shift
[ -z "$item" ] && die "$errmsg" [ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo."
todo=$(sed "$item!d" "$TODO_FILE") if [[ -z "$1" && $FORCE = 0 ]]; then
[ -z "$todo" ] && die "$item: No such todo." echo -n "Prepend: "
read input
else
input=$*
fi
if [[ -z "$1" && $FORCE = 0 ]]; then if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
echo -n "Prepend: " newtodo=$(sed "$item!d" "$TODO_FILE")
read input [[ $VERBOSE = 1 ]] && echo "$item: $newtodo"
else else
input=$* echo "TODO: Error prepending task $item."
fi fi
cleanup;;
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
newtodo=$(sed "$item!d" "$TODO_FILE")
[[ $VERBOSE = 1 ]] && echo "$item: $newtodo"
else
echo "TODO: Error prepending task $item."
fi
cleanup;;
"pri" | "p" ) "pri" | "p" )
item=$2 item=$2
newpri=$( printf "%s\n" "$3" | tr 'a-z' 'A-Z' ) newpri=$( printf "%s\n" "$3" | tr 'a-z' 'A-Z' )
errmsg="usage: $0 pri ITEM# PRIORITY errmsg="usage: $0 pri ITEM# PRIORITY
note: PRIORITY must be anywhere from A to Z." note: PRIORITY must be anywhere from A to Z."
[ "$#" -ne 3 ] && die "$errmsg" [ "$#" -ne 3 ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
[[ "$newpri" = +([A-Z]) ]] || die "$errmsg" [[ "$newpri" = +([A-Z]) ]] || die "$errmsg"
sed -e $item"s/^(.*) //" -e $item"s/^/($newpri) /" "$TODO_FILE" > /dev/null 2>&1 sed -e $item"s/^(.*) //" -e $item"s/^/($newpri) /" "$TODO_FILE" > /dev/null 2>&1
if [ "$?" -eq 0 ]; then if [ "$?" -eq 0 ]; then
#it's all good, continue #it's all good, continue
sed -i.bak -e $2"s/^(.*) //" -e $2"s/^/($newpri) /" "$TODO_FILE" sed -i.bak -e $2"s/^(.*) //" -e $2"s/^/($newpri) /" "$TODO_FILE"
NEWTODO=$(sed "$2!d" "$TODO_FILE") NEWTODO=$(sed "$2!d" "$TODO_FILE")
[[ $VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`" [[ $VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`"
[[ $VERBOSE = 1 ]] && echo "TODO: $item prioritized ($newpri)." [[ $VERBOSE = 1 ]] && echo "TODO: $item prioritized ($newpri)."
cleanup cleanup
else else
die "$errmsg" die "$errmsg"
fi;; fi;;
"replace" ) "replace" )
errmsg="usage: $0 replace ITEM# \"UPDATED ITEM\"" errmsg="usage: $0 replace ITEM# \"UPDATED ITEM\""
shift; item=$1; shift shift; item=$1; shift
[ -z "$item" ] && die "$errmsg" [ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg" [[ "$item" = +([0-9]) ]] || die "$errmsg"
todo=$(sed "$item!d" "$TODO_FILE") todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo." [ -z "$todo" ] && die "$item: No such todo."
if [[ -z "$1" && $FORCE = 0 ]]; then
echo -n "Replacement: "
read input
else
input=$*
fi
if [[ -z "$1" && $FORCE = 0 ]]; then sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
echo -n "Replacement: " [[ $VERBOSE = 1 ]] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
read input [[ $VERBOSE = 1 ]] && echo "replaced with"
else [[ $VERBOSE = 1 ]] && echo "$item: $NEWTODO"
input=$* cleanup;;
fi
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
[[ $VERBOSE = 1 ]] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
[[ $VERBOSE = 1 ]] && echo "replaced with"
[[ $VERBOSE = 1 ]] && echo "$item: $NEWTODO"
cleanup;;
"report" ) "report" )
#archive first #archive first
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE" sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
sed -i.bak '/^x /d' "$TODO_FILE" sed -i.bak '/^x /d' "$TODO_FILE"
NUMLINES=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') NUMLINES=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
if [ $NUMLINES = "0" ]; then if [ $NUMLINES = "0" ]; then
echo "datetime todos dones" >> "$REPORT_FILE" echo "datetime todos dones" >> "$REPORT_FILE"
fi fi
#now report #now report
TOTAL=$(cat "$TODO_FILE" | wc -l | sed 's/^[ \t]*//') TOTAL=$(cat "$TODO_FILE" | wc -l | sed 's/^[ \t]*//')
TDONE=$(cat "$DONE_FILE" | wc -l | sed 's/^[ \t]*//') TDONE=$(cat "$DONE_FILE" | wc -l | sed 's/^[ \t]*//')
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo $TOTAL; echo ' '; TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo $TOTAL; echo ' ';
echo $TDONE) echo $TDONE)
echo $TECHO >> "$REPORT_FILE" echo $TECHO >> "$REPORT_FILE"
[[ $VERBOSE = 1 ]] && echo "TODO: Report file updated." [[ $VERBOSE = 1 ]] && echo "TODO: Report file updated."
cat "$REPORT_FILE" cat "$REPORT_FILE"
cleanup;; cleanup;;
* ) * )
usage usage
if [ -d "$HOME/.todo.actions.d" ] if [ -d "$HOME/.todo.actions.d" ]; then
then if [ -x "$HOME/.todo.actions.d/$action" ]; then
if [ -x "$HOME/.todo.actions.d/$action" ] CFG_FILE="$CFG_FILE" "$HOME/.todo.actions.d/$action" "$@"
then else
CFG_FILE="$CFG_FILE" "$HOME/.todo.actions.d/$action" "$@" usage
else fi
usage else
fi usage
else fi
usage
fi
esac esac