Run .todo.actions.d Before Builtins
. Let users override default commands by creating a script in ~/.todo.actions.d/ with the same name as a default command. Idea by Don Harper and David A. Harding; patch by Harding. . The patch adds the following logic and increases the indent level for the case statement: . +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
This commit is contained in:
61
todo.sh
61
todo.sh
@@ -332,8 +332,12 @@ 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' )
|
||||||
|
|
||||||
case $action in
|
if [ -d "$HOME/.todo.actions.d" -a -x "$HOME/.todo.actions.d/$action" ]
|
||||||
"add" | "a")
|
then
|
||||||
|
CFG_FILE="$CFG_FILE" "$HOME/.todo.actions.d/$action" "$@"
|
||||||
|
else
|
||||||
|
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
|
||||||
@@ -352,7 +356,7 @@ case $action in
|
|||||||
[[ $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\""
|
||||||
@@ -369,7 +373,7 @@ case $action in
|
|||||||
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
|
||||||
|
|
||||||
@@ -391,10 +395,10 @@ case $action in
|
|||||||
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
|
||||||
@@ -433,7 +437,7 @@ case $action in
|
|||||||
[[ $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#"
|
||||||
|
|
||||||
@@ -454,7 +458,7 @@ case $action in
|
|||||||
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"
|
||||||
@@ -477,7 +481,7 @@ case $action in
|
|||||||
cleanup ;;
|
cleanup ;;
|
||||||
|
|
||||||
|
|
||||||
"list" | "ls" )
|
"list" | "ls" )
|
||||||
item=$2
|
item=$2
|
||||||
if [ -z "$item" ]; then
|
if [ -z "$item" ]; then
|
||||||
echo "--"
|
echo "--"
|
||||||
@@ -511,7 +515,7 @@ case $action in
|
|||||||
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"
|
||||||
|
|
||||||
@@ -537,7 +541,7 @@ case $action in
|
|||||||
cleanup ;;
|
cleanup ;;
|
||||||
|
|
||||||
|
|
||||||
"listfile" | "lf" )
|
"listfile" | "lf" )
|
||||||
src="$TODO_DIR/$2"
|
src="$TODO_DIR/$2"
|
||||||
|
|
||||||
if [ -z "$3" ]; then
|
if [ -z "$3" ]; then
|
||||||
@@ -569,19 +573,19 @@ case $action in
|
|||||||
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]\)
|
||||||
@@ -602,7 +606,7 @@ note: PRIORITY must a single letter from A to Z."
|
|||||||
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
|
||||||
@@ -651,7 +655,7 @@ note: PRIORITY must a single letter from A to Z."
|
|||||||
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
|
||||||
|
|
||||||
@@ -676,12 +680,12 @@ note: PRIORITY must a single letter from A to Z."
|
|||||||
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"
|
||||||
@@ -700,7 +704,7 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
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
|
||||||
|
|
||||||
@@ -723,7 +727,7 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
[[ $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"
|
||||||
@@ -742,15 +746,8 @@ note: PRIORITY must be anywhere from A to Z."
|
|||||||
cat "$REPORT_FILE"
|
cat "$REPORT_FILE"
|
||||||
cleanup;;
|
cleanup;;
|
||||||
|
|
||||||
* )
|
* )
|
||||||
usage
|
usage
|
||||||
if [ -d "$HOME/.todo.actions.d" ]; then
|
;;
|
||||||
if [ -x "$HOME/.todo.actions.d/$action" ]; then
|
esac
|
||||||
CFG_FILE="$CFG_FILE" "$HOME/.todo.actions.d/$action" "$@"
|
fi
|
||||||
else
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
esac
|
|
||||||
|
|||||||
Reference in New Issue
Block a user