Added -vv For Debugging Output

This commit is contained in:
David A. Harding
2009-03-17 14:07:48 -04:00
parent 07bb979d43
commit 39ee9ab045

59
todo.sh
View File

@@ -150,6 +150,8 @@ help()
when it's added. when it's added.
-v -v
Verbose mode turns on confirmation messages Verbose mode turns on confirmation messages
-vv
Extra verbose mode prints some debugging information
-V -V
Displays version, license and credits Displays version, license and credits
@@ -197,13 +199,13 @@ archive()
{ {
#defragment blank lines #defragment blank lines
sed -i.bak -e '/./!d' "$TODO_FILE" sed -i.bak -e '/./!d' "$TODO_FILE"
[[ $TODOTXT_VERBOSE = 1 ]] && grep "^x " "$TODO_FILE" [ $TODOTXT_VERBOSE -gt 0 ] && 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"
#[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: Duplicate tasks have been removed." #[[ $TODOTXT_VERBOSE -gt 0 ]] && echo "TODO: Duplicate tasks have been removed."
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $TODO_FILE archived." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $TODO_FILE archived."
cleanup cleanup
} }
@@ -282,7 +284,7 @@ do
TODOTXT_DATE_ON_ADD=1 TODOTXT_DATE_ON_ADD=1
;; ;;
v ) v )
TODOTXT_VERBOSE=1 : $(( TODOTXT_VERBOSE++ ))
;; ;;
V ) V )
version version
@@ -425,12 +427,16 @@ _list() {
) )
echo -ne "$command${command:+\n}" echo -ne "$command${command:+\n}"
if [ $TODOTXT_VERBOSE == 1 ]; then if [ $TODOTXT_VERBOSE -gt 0 ]; then
NUMTASKS=$( echo -ne "$command" | sed -n '$ =' ) NUMTASKS=$( echo -ne "$command" | sed -n '$ =' )
echo "--" echo "--"
echo "TODO: ${NUMTASKS:-0} of $LINES tasks shown from $FILE" echo "TODO: ${NUMTASKS:-0} of $LINES tasks shown from $FILE"
fi fi
if [ $TODOTXT_VERBOSE -gt 1 ]
then
echo "TODO DEBUG: Filter Command was: ${filter_command:-cat}"
fi
} }
export -f _list export -f _list
@@ -472,7 +478,7 @@ case $action in
fi fi
echo "$input" >> "$TODO_FILE" echo "$input" >> "$TODO_FILE"
TASKNUM=$(sed -n '$ =' "$TODO_FILE") TASKNUM=$(sed -n '$ =' "$TODO_FILE")
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;; cleanup;;
"addto" ) "addto" )
@@ -486,7 +492,7 @@ case $action in
if [ -f "$dest" ]; then if [ -f "$dest" ]; then
echo "$input" >> "$dest" echo "$input" >> "$dest"
TASKNUM=$(sed -n '$ =' "$dest") TASKNUM=$(sed -n '$ =' "$dest")
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added to $dest on line $TASKNUM." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$input' added to $dest on line $TASKNUM."
else else
echo "TODO: Destination file $dest does not exist." echo "TODO: Destination file $dest does not exist."
fi fi
@@ -508,7 +514,7 @@ case $action in
fi fi
if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then if sed -i.bak $item" s|^.*|& $input|" "$TODO_FILE"; then
newtodo=$(sed "$item!d" "$TODO_FILE") newtodo=$(sed "$item!d" "$TODO_FILE")
[[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo" [ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
else else
echo "TODO: Error appending task $item." echo "TODO: Error appending task $item."
fi fi
@@ -543,7 +549,7 @@ case $action in
# 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
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$DELETEME' deleted." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$DELETEME' deleted."
cleanup cleanup
else else
echo "TODO: No tasks were deleted." echo "TODO: No tasks were deleted."
@@ -553,7 +559,7 @@ case $action in
fi fi
else else
sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE" sed -i.bak -e $item"s/$3/ /g" "$TODO_FILE"
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $3 removed from $item." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $3 removed from $item."
fi ;; fi ;;
"depri" | "dp" ) "depri" | "dp" )
@@ -570,8 +576,8 @@ case $action in
#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")
[[ $TODOTXT_VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`" [ $TODOTXT_VERBOSE -gt 0 ] && echo -e "`echo "$item: $NEWTODO"`"
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item deprioritized." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item deprioritized."
cleanup cleanup
else else
die "$errmsg" die "$errmsg"
@@ -591,8 +597,8 @@ case $action in
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")
[[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo" [ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item marked as done." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item marked as done."
if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
archive archive
@@ -636,23 +642,22 @@ case $action in
"listpri" | "lsp" ) "listpri" | "lsp" )
shift ## was "listpri" shift ## was "listpri", new $1 is priority to list
if [ "${1:-}" ] if [ "${1:-}" ]
then then
## A priority was specified ## A priority was specified
pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || { pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || {
die "usage: $0 listpri PRIORITY die "usage: $0 listpri PRIORITY
note: PRIORITY must a single letter from A to Z." note: PRIORITY must a single letter from A to Z."
} }
else else
## No priority specified; show all priority tasks ## No priority specified; show all priority tasks
pri="[A-Z]" pri="[A-Z]"
fi fi
pri="($pri)" pri="($pri)"
shift ## was priority
_list "$TODO_FILE" "$pri" "$@" _list "$TODO_FILE" "$pri"
;; ;;
"move" | "mv" ) "move" | "mv" )
@@ -688,7 +693,7 @@ case $action in
fi fi
echo "$MOVEME" >> "$dest" echo "$MOVEME" >> "$dest"
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
cleanup cleanup
else else
echo "TODO: No tasks moved." echo "TODO: No tasks moved."
@@ -723,7 +728,7 @@ case $action in
if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then if sed -i.bak $item" s|^.*|$input &|" "$TODO_FILE"; then
newtodo=$(sed "$item!d" "$TODO_FILE") newtodo=$(sed "$item!d" "$TODO_FILE")
[[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo" [ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $newtodo"
else else
echo "TODO: Error prepending task $item." echo "TODO: Error prepending task $item."
fi fi
@@ -746,8 +751,8 @@ note: PRIORITY must be anywhere from A to Z."
#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")
[[ $TODOTXT_VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`" [ $TODOTXT_VERBOSE -gt 0 ] && echo -e "`echo "$item: $NEWTODO"`"
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item prioritized ($newpri)." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: $item prioritized ($newpri)."
cleanup cleanup
else else
die "$errmsg" die "$errmsg"
@@ -771,9 +776,9 @@ note: PRIORITY must be anywhere from A to Z."
fi fi
sed -i.bak $item" s|^.*|$input|" "$TODO_FILE" sed -i.bak $item" s|^.*|$input|" "$TODO_FILE"
[[ $TODOTXT_VERBOSE = 1 ]] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1) [ $TODOTXT_VERBOSE -gt 0 ] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
[[ $TODOTXT_VERBOSE = 1 ]] && echo "replaced with" [ $TODOTXT_VERBOSE -gt 0 ] && echo "replaced with"
[[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $NEWTODO" [ $TODOTXT_VERBOSE -gt 0 ] && echo "$item: $NEWTODO"
cleanup;; cleanup;;
"report" ) "report" )
@@ -791,7 +796,7 @@ note: PRIORITY must be anywhere from A to Z."
TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo ${TOTAL:-0}; echo ' '; TECHO=$(echo $(date +%Y-%m-%d-%T); echo ' '; echo ${TOTAL:-0}; echo ' ';
echo ${TDONE:-0}) echo ${TDONE:-0})
echo $TECHO >> "$REPORT_FILE" echo $TECHO >> "$REPORT_FILE"
[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: Report file updated." [ $TODOTXT_VERBOSE -gt 0 ] && echo "TODO: Report file updated."
cat "$REPORT_FILE" cat "$REPORT_FILE"
cleanup;; cleanup;;