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 == # == HANDLE ACTION ==
action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' ) 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" ] if [ -d "$HOME/.todo.actions.d" -a -x "$HOME/.todo.actions.d/$action" ]
then then
CFG_FILE="$CFG_FILE" "$HOME/.todo.actions.d/$action" "$@" CFG_FILE="$CFG_FILE" "$HOME/.todo.actions.d/$action" "$@"
else cleanup
case $action in fi
"add" | "a")
## Only run if $action isn't found in .todo.actions.d
case $action in
"add" | "a")
if [[ -z "$2" && $FORCE = 0 ]]; then if [[ -z "$2" && $FORCE = 0 ]]; then
echo -n "Add: " echo -n "Add: "
read input read input
@@ -347,7 +351,7 @@ else
[[ $VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM." [[ $VERBOSE = 1 ]] && echo "TODO: '$input' added on line $TASKNUM."
cleanup;; 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\"" [ -z "$3" ] && die "usage: $0 addto DEST \"TODO ITEM\""
@@ -364,7 +368,7 @@ else
fi fi
cleanup;; 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
@@ -386,10 +390,10 @@ else
fi fi
cleanup;; 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
@@ -428,7 +432,7 @@ else
[[ $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#"
@@ -449,7 +453,7 @@ 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"
@@ -472,7 +476,7 @@ else
cleanup ;; cleanup ;;
"list" | "ls" ) "list" | "ls" )
item=$2 item=$2
if [ -z "$item" ]; then if [ -z "$item" ]; then
echo -e "$( \ echo -e "$( \
@@ -524,7 +528,7 @@ else
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"
@@ -544,7 +548,7 @@ else
cleanup ;; cleanup ;;
"listfile" | "lf" ) "listfile" | "lf" )
src="$TODO_DIR/$2" src="$TODO_DIR/$2"
if [ -z "$3" ]; then if [ -z "$3" ]; then
@@ -576,19 +580,19 @@ else
fi fi
cleanup ;; 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]\)
@@ -609,7 +613,7 @@ else
fi fi
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 PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $0 mv ITEM# DEST [SRC]" errmsg="usage: $0 mv ITEM# DEST [SRC]"
item=$2 item=$2
@@ -658,7 +662,7 @@ else
fi fi
cleanup;; 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
@@ -683,12 +687,12 @@ else
fi fi
cleanup;; 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"
@@ -707,7 +711,7 @@ 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
@@ -730,7 +734,7 @@ else
[[ $VERBOSE = 1 ]] && echo "$item: $NEWTODO" [[ $VERBOSE = 1 ]] && echo "$item: $NEWTODO"
cleanup;; 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"
@@ -749,8 +753,7 @@ else
cat "$REPORT_FILE" cat "$REPORT_FILE"
cleanup;; cleanup;;
* ) * )
usage usage
;; ;;
esac esac
fi