Exit If .todo.actions.d Script Is Run

.
Suggested by Philippe Teuwen, this patch undoes a lot of the unnecessary
formating changes in my previous patch.
This commit is contained in:
David A. Harding
2009-03-08 11:46:26 -04:00
parent e6649e6293
commit 98646a575a

53
todo.sh
View File

@@ -323,12 +323,16 @@ shopt -s extglob
# == HANDLE ACTION ==
action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' )
## Run and quit if there's a actions script
if [ -d "$HOME/.todo.actions.d" -a -x "$HOME/.todo.actions.d/$action" ]
then
CFG_FILE="$CFG_FILE" "$HOME/.todo.actions.d/$action" "$@"
else
case $action in
"add" | "a")
cleanup
fi
## Only run if $action isn't found in .todo.actions.d
case $action in
"add" | "a")
if [[ -z "$2" && $FORCE = 0 ]]; then
echo -n "Add: "
read input
@@ -347,7 +351,7 @@ else
[[ $VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;;
"addto" )
"addto" )
[ -z "$2" ] && die "usage: $0 addto DEST \"TODO ITEM\""
dest="$TODO_DIR/$2"
[ -z "$3" ] && die "usage: $0 addto DEST \"TODO ITEM\""
@@ -364,7 +368,7 @@ else
fi
cleanup;;
"append" | "app" )
"append" | "app" )
errmsg="usage: $0 append ITEM# \"TEXT TO APPEND\""
shift; item=$1; shift
@@ -386,10 +390,10 @@ else
fi
cleanup;;
"archive" )
"archive" )
archive;;
"del" | "rm" )
"del" | "rm" )
# replace deleted line with a blank line when PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $0 del ITEM#"
item=$2
@@ -428,7 +432,7 @@ else
[[ $VERBOSE = 1 ]] && echo "TODO: $3 removed from $item."
fi ;;
"depri" | "dp" )
"depri" | "dp" )
item=$2
errmsg="usage: $0 depri ITEM#"
@@ -449,7 +453,7 @@ else
die "$errmsg"
fi;;
"do" )
"do" )
errmsg="usage: $0 do ITEM#"
item=$2
[ -z "$item" ] && die "$errmsg"
@@ -472,7 +476,7 @@ else
cleanup ;;
"list" | "ls" )
"list" | "ls" )
item=$2
if [ -z "$item" ]; then
echo -e "$( \
@@ -524,7 +528,7 @@ else
fi
cleanup ;;
"listall" | "lsa" )
"listall" | "lsa" )
item=$2
cat "$TODO_FILE" "$DONE_FILE" > "$TMP_FILE"
@@ -544,7 +548,7 @@ else
cleanup ;;
"listfile" | "lf" )
"listfile" | "lf" )
src="$TODO_DIR/$2"
if [ -z "$3" ]; then
@@ -576,19 +580,19 @@ else
fi
cleanup ;;
"listcon" | "lsc" )
"listcon" | "lsc" )
gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '@' | sort | uniq
cleanup ;;
"listproj" | "lsprj" )
"listproj" | "lsprj" )
gawk '{for(i = 1; i <= NF; i++) print $i}' "$TODO_FILE" | grep '+' | sort | uniq
cleanup ;;
"listpri" | "lsp" )
"listpri" | "lsp" )
pri=$( printf "%s\n" "$2" | tr 'a-z' 'A-Z' )
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
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]\)
@@ -609,7 +613,7 @@ else
fi
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
@@ -658,7 +662,7 @@ else
fi
cleanup;;
"prepend" | "prep" )
"prepend" | "prep" )
errmsg="usage: $0 prepend ITEM# \"TEXT TO PREPEND\""
shift; item=$1; shift
@@ -683,12 +687,12 @@ else
fi
cleanup;;
"pri" | "p" )
"pri" | "p" )
item=$2
newpri=$( printf "%s\n" "$3" | tr 'a-z' 'A-Z' )
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"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
@@ -707,7 +711,7 @@ else
die "$errmsg"
fi;;
"replace" )
"replace" )
errmsg="usage: $0 replace ITEM# \"UPDATED ITEM\""
shift; item=$1; shift
@@ -730,7 +734,7 @@ else
[[ $VERBOSE = 1 ]] && echo "$item: $NEWTODO"
cleanup;;
"report" )
"report" )
#archive first
sed '/^x /!d' "$TODO_FILE" >> "$DONE_FILE"
sed -i.bak '/^x /d' "$TODO_FILE"
@@ -749,8 +753,7 @@ else
cat "$REPORT_FILE"
cleanup;;
* )
* )
usage
;;
esac
fi
esac