Uniformly use $TODO_SH to refer to script.

Set $TODO_SH to just be $(basename "$0") at the beginning
of the script and use it in all usage messages.

This happens to simplify testing because it allows us to refer to
the script as "todo.sh" in all output.  For general use, if the
user has aliased to file to something else, the usage messages will
still reflect that alias.

Signed-off-by: Emil Sit <sit@emilsit.net>
This commit is contained in:
Emil Sit
2009-04-18 21:11:27 -04:00
parent 825c60514f
commit fee3133547
4 changed files with 21 additions and 20 deletions

View File

@@ -14,7 +14,7 @@ todo.sh add notice the daisies > /dev/null
test_todo_session 'replace usage' <<EOF
>>> todo.sh replace adf asdfa
=== 1
usage: $(which todo.sh) replace ITEM# "UPDATED ITEM"
usage: todo.sh replace ITEM# "UPDATED ITEM"
EOF
test_todo_session 'basic replace' <<EOF

View File

@@ -6,7 +6,7 @@ test_description='basic priority functionality
test_todo_session 'priority usage' <<EOF
>>> todo.sh pri B B
usage: $HOME/bin/todo.sh pri ITEM# PRIORITY
usage: todo.sh pri ITEM# PRIORITY
note: PRIORITY must be anywhere from A to Z.
=== 1
EOF

View File

@@ -92,7 +92,7 @@ TODO: Report file updated.
2009-02-13-04:40:00 5 1
>>> todo.sh append g a
usage: $HOME/bin/todo.sh append ITEM# "TEXT TO APPEND"
usage: todo.sh append ITEM# "TEXT TO APPEND"
=== 1
>>> todo.sh append 2 and think

35
todo.sh
View File

@@ -17,13 +17,17 @@ EndVersion
exit 1
}
oneline_usage="todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]"
# Set script name early.
TODO_SH=$(basename "$0")
export TODO_SH
oneline_usage="$TODO_SH [-fhpantvV] [-d todo_config] action [task_number] [task_description]"
usage()
{
sed -e 's/^ //' <<EndUsage
Usage: $oneline_usage
Try 'todo.sh -h' for more information.
Try '$TODO_SH -h' for more information.
EndUsage
exit 1
}
@@ -387,9 +391,6 @@ then
export TODO_ACTIONS_DIR
fi
TODO_SH="$0"
export TODO_SH
# === SANITY CHECKS (thanks Karl!) ===
[ -r "$TODOTXT_CFG_FILE" ] || die "Fatal error: Cannot read configuration file $TODOTXT_CFG_FILE"
@@ -552,7 +553,7 @@ case $action in
echo -n "Add: "
read input
else
[ -z "$2" ] && die "usage: $0 add \"TODO ITEM\""
[ -z "$2" ] && die "usage: $TODO_SH add \"TODO ITEM\""
shift
input=$*
fi
@@ -567,9 +568,9 @@ case $action in
cleanup;;
"addto" )
[ -z "$2" ] && die "usage: $0 addto DEST \"TODO ITEM\""
[ -z "$2" ] && die "usage: $TODO_SH0 addto DEST \"TODO ITEM\""
dest="$TODO_DIR/$2"
[ -z "$3" ] && die "usage: $0 addto DEST \"TODO ITEM\""
[ -z "$3" ] && die "usage: $TODO_SH0 addto DEST \"TODO ITEM\""
shift
shift
input=$*
@@ -584,7 +585,7 @@ case $action in
cleanup;;
"append" | "app" )
errmsg="usage: $0 append ITEM# \"TEXT TO APPEND\""
errmsg="usage: $TODO_SH append ITEM# \"TEXT TO APPEND\""
shift; item=$1; shift
[ -z "$item" ] && die "$errmsg"
@@ -610,7 +611,7 @@ case $action in
"del" | "rm" )
# replace deleted line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $0 del ITEM#"
errmsg="usage: $TODO_SH del ITEM#"
item=$2
[ -z "$item" ] && die "$errmsg"
@@ -649,7 +650,7 @@ case $action in
"depri" | "dp" )
item=$2
errmsg="usage: $0 depri ITEM#"
errmsg="usage: $TODO_SH depri ITEM#"
todo=$(sed "$item!d" "$TODO_FILE")
[ -z "$todo" ] && die "$item: No such todo."
@@ -669,7 +670,7 @@ case $action in
fi;;
"do" )
errmsg="usage: $0 do ITEM#"
errmsg="usage: $TODO_SH do ITEM#"
item=$2
[ -z "$item" ] && die "$errmsg"
[[ "$item" = +([0-9]) ]] || die "$errmsg"
@@ -736,7 +737,7 @@ case $action in
then
## A priority was specified
pri=$( printf "%s\n" "$1" | tr 'a-z' 'A-Z' | grep '^[A-Z]$' ) || {
die "usage: $0 listpri PRIORITY
die "usage: $TODO_SH listpri PRIORITY
note: PRIORITY must a single letter from A to Z."
}
else
@@ -750,7 +751,7 @@ case $action in
"move" | "mv" )
# replace moved line with a blank line when TODOTXT_PRESERVE_LINE_NUMBERS is 1
errmsg="usage: $0 mv ITEM# DEST [SRC]"
errmsg="usage: $TODO_SH mv ITEM# DEST [SRC]"
item=$2
dest="$TODO_DIR/$3"
src="$TODO_DIR/$4"
@@ -798,7 +799,7 @@ case $action in
cleanup;;
"prepend" | "prep" )
errmsg="usage: $0 prepend ITEM# \"TEXT TO PREPEND\""
errmsg="usage: $TODO_SH prepend ITEM# \"TEXT TO PREPEND\""
shift; item=$1; shift
[ -z "$item" ] && die "$errmsg"
@@ -826,7 +827,7 @@ case $action in
item=$2
newpri=$( printf "%s\n" "$3" | tr 'a-z' 'A-Z' )
errmsg="usage: $0 pri ITEM# PRIORITY
errmsg="usage: $TODO_SH pri ITEM# PRIORITY
note: PRIORITY must be anywhere from A to Z."
[ "$#" -ne 3 ] && die "$errmsg"
@@ -847,7 +848,7 @@ note: PRIORITY must be anywhere from A to Z."
fi;;
"replace" )
errmsg="usage: $0 replace ITEM# \"UPDATED ITEM\""
errmsg="usage: $TODO_SH replace ITEM# \"UPDATED ITEM\""
shift; item=$1; shift
[ -z "$item" ] && die "$errmsg"