Options & environment variables: add namespace & allow for preset

This patch does 2 things:
- Allowing environment variables corresponding to options (e.g. VERBOSE for -v)
to be predefined in the user environment instead of having to always use
the corresponding option.
- Adding namespace TODOTXT_ to those envvars to avoid clashes in user environment

todo.action.d scripts can call recursively todo.sh and this patch preserves
the options/envvars through the calls.
As a bonus, now the user can export in advance one of those variables in
his/her environment and it would have the same effect as using the todo.sh
corresponding option.

export TODOTXT_AUTO_ARCHIVE=0          is same as option -a
export TODOTXT_CFG_FILE=CONFIG_FILE    is same as option -d CONFIG_FILE
export TODOTXT_FORCE=1                 is same as option -f
export TODOTXT_PRESERVE_LINE_NUMBERS=0 is same as option -n
export TODOTXT_PLAIN=1                 is same as option -p
export TODOTXT_DATE_ON_ADD=1           is same as option -t
export TODOTXT_VERBOSE=1               is same as option -v

Signed-off-by: Gina Trapani <ginatrapani@gmail.com>
This commit is contained in:
Philippe Teuwen
2009-03-09 06:08:09 +08:00
committed by Gina Trapani
parent f37cedc7ca
commit 2bd2e9f7bd

128
todo.sh Normal file → Executable file
View File

@@ -139,6 +139,16 @@ help()
Verbose mode turns on confirmation messages Verbose mode turns on confirmation messages
-V -V
Displays version, license and credits Displays version, license and credits
Environment variables:
TODOTXT_AUTO_ARCHIVE=0 is same as option -a
TODOTXT_CFG_FILE=CONFIG_FILE is same as option -d CONFIG_FILE
TODOTXT_FORCE=1 is same as option -f
TODOTXT_PRESERVE_LINE_NUMBERS=0 is same as option -n
TODOTXT_PLAIN=1 is same as option -p
TODOTXT_DATE_ON_ADD=1 is same as option -t
TODOTXT_VERBOSE=1 is same as option -v
EndHelp EndHelp
if [ -d "$HOME/.todo.actions.d" ] if [ -d "$HOME/.todo.actions.d" ]
@@ -174,55 +184,44 @@ 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" [[ $TODOTXT_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." #[[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: Duplicate tasks have been removed."
[[ $VERBOSE = 1 ]] && echo "TODO: $TODO_FILE archived." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $TODO_FILE archived."
cleanup cleanup
} }
# == PROCESS OPTIONS == # == PROCESS OPTIONS ==
# defaults
VERBOSE=1
PLAIN=0
CFG_FILE=$HOME/todo.cfg
FORCE=0
PRESERVE_LINE_NUMBERS=1
AUTO_ARCHIVE=1
DATE_ON_ADD=0
export VERBOSE PLAIN CFG_FILE FORCE PRESERVE_LINE_NUMBERS AUTO_ARCHIVE DATE_ON_ADD
while getopts ":fhpnatvVd:" Option while getopts ":fhpnatvVd:" Option
do do
case $Option in case $Option in
a ) a )
AUTO_ARCHIVE=0 TODOTXT_AUTO_ARCHIVE=0
;; ;;
d ) d )
CFG_FILE=$OPTARG TODOTXT_CFG_FILE=$OPTARG
;; ;;
f ) f )
FORCE=1 TODOTXT_FORCE=1
;; ;;
h ) h )
help help
;; ;;
n ) n )
PRESERVE_LINE_NUMBERS=0 TODOTXT_PRESERVE_LINE_NUMBERS=0
;; ;;
p ) p )
PLAIN=1 TODOTXT_PLAIN=1
;; ;;
t ) t )
DATE_ON_ADD=1 TODOTXT_DATE_ON_ADD=1
;; ;;
v ) v )
VERBOSE=1 TODOTXT_VERBOSE=1
;; ;;
V ) V )
version version
@@ -231,19 +230,30 @@ do
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
[ -e "$CFG_FILE" ] || { # defaults if not yet defined
TODOTXT_VERBOSE=${TODOTXT_VERBOSE:-1}
TODOTXT_PLAIN=${TODOTXT_PLAIN:-0}
TODOTXT_CFG_FILE=${TODOTXT_CFG_FILE:-$HOME/todo.cfg}
TODOTXT_FORCE=${TODOTXT_FORCE:-0}
TODOTXT_PRESERVE_LINE_NUMBERS=${TODOTXT_PRESERVE_LINE_NUMBERS:-1}
TODOTXT_AUTO_ARCHIVE=${TODOTXT_AUTO_ARCHIVE:-1}
TODOTXT_DATE_ON_ADD=${TODOTXT_DATE_ON_ADD:-0}
[ -e "$TODOTXT_CFG_FILE" ] || {
CFG_FILE_ALT="$HOME/.todo.cfg" CFG_FILE_ALT="$HOME/.todo.cfg"
if [ -e "$CFG_FILE_ALT" ] if [ -e "$CFG_FILE_ALT" ]
then then
CFG_FILE="$CFG_FILE_ALT" TODOTXT_CFG_FILE="$CFG_FILE_ALT"
fi fi
} }
# === SANITY CHECKS (thanks Karl!) === export TODOTXT_VERBOSE TODOTXT_PLAIN TODOTXT_CFG_FILE TODOTXT_FORCE TODOTXT_PRESERVE_LINE_NUMBERS TODOTXT_AUTO_ARCHIVE TODOTXT_DATE_ON_ADD
[ -r "$CFG_FILE" ] || die "Fatal error: Cannot read configuration file $CFG_FILE"
. "$CFG_FILE" # === SANITY CHECKS (thanks Karl!) ===
[ -r "$TODOTXT_CFG_FILE" ] || die "Fatal error: Cannot read configuration file $TODOTXT_CFG_FILE"
. "$TODOTXT_CFG_FILE"
[ -z "$1" ] && usage [ -z "$1" ] && usage
[ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory" [ -d "$TODO_DIR" ] || die "Fatal Error: $TODO_DIR is not a directory"
@@ -254,7 +264,7 @@ 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 [ $TODOTXT_PLAIN = 1 ]; then
PRI_A=$NONE PRI_A=$NONE
PRI_B=$NONE PRI_B=$NONE
PRI_C=$NONE PRI_C=$NONE
@@ -270,7 +280,7 @@ 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" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Add: " echo -n "Add: "
read input read input
else else
@@ -279,13 +289,13 @@ case $action in
input=$* input=$*
fi fi
if [[ $DATE_ON_ADD = 1 ]]; then if [[ $TODOTXT_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" echo "$input" >> "$TODO_FILE"
TASKNUM=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') TASKNUM=$(wc -l "$TODO_FILE" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
[[ $VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;; cleanup;;
"addto" ) "addto" )
@@ -299,7 +309,7 @@ case $action in
if [ -f "$dest" ]; then if [ -f "$dest" ]; then
echo "$input" >> "$dest" echo "$input" >> "$dest"
TASKNUM=$(wc -l "$dest" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/') TASKNUM=$(wc -l "$dest" | sed 's/^[[:space:]]*\([0-9]*\).*/\1/')
[[ $VERBOSE = 1 ]] && echo "TODO: '$input' added to $dest on line $TASKNUM." [[ $TODOTXT_VERBOSE = 1 ]] && 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
@@ -313,7 +323,7 @@ case $action in
[[ "$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 if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Append: " echo -n "Append: "
read input read input
else else
@@ -321,7 +331,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")
[[ $VERBOSE = 1 ]] && echo "$item: $newtodo" [[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo"
else else
echo "TODO: Error appending task $item." echo "TODO: Error appending task $item."
fi fi
@@ -331,7 +341,7 @@ case $action in
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 TODOTXT_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"
@@ -342,21 +352,21 @@ case $action in
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 [ $TODOTXT_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 [ $TODOTXT_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." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$DELETEME' deleted."
cleanup cleanup
else else
echo "TODO: No tasks were deleted." echo "TODO: No tasks were deleted."
@@ -366,7 +376,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"
[[ $VERBOSE = 1 ]] && echo "TODO: $3 removed from $item." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $3 removed from $item."
fi ;; fi ;;
"depri" | "dp" ) "depri" | "dp" )
@@ -383,8 +393,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")
[[ $VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`" [[ $TODOTXT_VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`"
[[ $VERBOSE = 1 ]] && echo "TODO: $item deprioritized." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item deprioritized."
cleanup cleanup
else else
die "$errmsg" die "$errmsg"
@@ -404,10 +414,10 @@ 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")
[[ $VERBOSE = 1 ]] && echo "$item: $newtodo" [[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo"
[[ $VERBOSE = 1 ]] && echo "TODO: $item marked as done." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item marked as done."
if [ $AUTO_ARCHIVE = 1 ]; then if [ $TODOTXT_AUTO_ARCHIVE = 1 ]; then
archive archive
fi fi
cleanup ;; cleanup ;;
@@ -464,7 +474,7 @@ case $action in
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 [ $TODOTXT_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."
@@ -501,7 +511,7 @@ 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 [ $TODOTXT_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."
@@ -510,7 +520,7 @@ note: PRIORITY must a single letter from A to Z."
[[ "$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 [ $TODOTXT_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."
@@ -519,7 +529,7 @@ note: PRIORITY must a single letter from A to Z."
cleanup;; cleanup;;
"move" | "mv" ) "move" | "mv" )
# replace moved line with a blank line when PRESERVE_LINE_NUMBERS is 1 # replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $0 mv ITEM# DEST [SRC]" errmsg="usage: $0 mv ITEM# DEST [SRC]"
item=$2 item=$2
dest="$TODO_DIR/$3" dest="$TODO_DIR/$3"
@@ -535,14 +545,14 @@ note: PRIORITY must a single letter from A to Z."
if [ -f "$dest" ]; then if [ -f "$dest" ]; then
if sed -ne "$item p" "$src" | grep "^."; then if sed -ne "$item p" "$src" | grep "^."; then
MOVEME=$(sed "$item!d" "$src") MOVEME=$(sed "$item!d" "$src")
if [ $FORCE = 0 ]; then if [ $TODOTXT_FORCE = 0 ]; then
echo "Move '$MOVEME' from $src to $dest? (y/n)" echo "Move '$MOVEME' from $src to $dest? (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 [ $TODOTXT_PRESERVE_LINE_NUMBERS = 0 ]; then
# delete line (changes line numbers) # delete line (changes line numbers)
sed -i.bak -e $item"s/^.*//" -e '/./!d' "$src" sed -i.bak -e $item"s/^.*//" -e '/./!d' "$src"
else else
@@ -551,7 +561,7 @@ note: PRIORITY must a single letter from A to Z."
fi fi
echo "$MOVEME" >> "$dest" echo "$MOVEME" >> "$dest"
[[ $VERBOSE = 1 ]] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: '$MOVEME' moved from '$src' to '$dest'."
cleanup cleanup
else else
echo "TODO: No tasks moved." echo "TODO: No tasks moved."
@@ -577,7 +587,7 @@ note: PRIORITY must a single letter from A to Z."
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 if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Prepend: " echo -n "Prepend: "
read input read input
else else
@@ -586,7 +596,7 @@ note: PRIORITY must a single letter from A to Z."
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")
[[ $VERBOSE = 1 ]] && echo "$item: $newtodo" [[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $newtodo"
else else
echo "TODO: Error prepending task $item." echo "TODO: Error prepending task $item."
fi fi
@@ -609,8 +619,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")
[[ $VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`" [[ $TODOTXT_VERBOSE = 1 ]] && echo -e "`echo "$item: $NEWTODO"`"
[[ $VERBOSE = 1 ]] && echo "TODO: $item prioritized ($newpri)." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: $item prioritized ($newpri)."
cleanup cleanup
else else
die "$errmsg" die "$errmsg"
@@ -626,7 +636,7 @@ note: PRIORITY must be anywhere from A to Z."
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 if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Replacement: " echo -n "Replacement: "
read input read input
else else
@@ -634,9 +644,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"
[[ $VERBOSE = 1 ]] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1) [[ $TODOTXT_VERBOSE = 1 ]] && NEWTODO=$(head -$item "$TODO_FILE" | tail -1)
[[ $VERBOSE = 1 ]] && echo "replaced with" [[ $TODOTXT_VERBOSE = 1 ]] && echo "replaced with"
[[ $VERBOSE = 1 ]] && echo "$item: $NEWTODO" [[ $TODOTXT_VERBOSE = 1 ]] && echo "$item: $NEWTODO"
cleanup;; cleanup;;
"report" ) "report" )
@@ -654,7 +664,7 @@ note: PRIORITY must be anywhere from A to Z."
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." [[ $TODOTXT_VERBOSE = 1 ]] && echo "TODO: Report file updated."
cat "$REPORT_FILE" cat "$REPORT_FILE"
cleanup;; cleanup;;