From 0f2e13d15b4e7a1ebd56b6e615762e0cb4540a92 Mon Sep 17 00:00:00 2001 From: Jaidyn Levesque Date: Sun, 26 Jan 2020 00:35:33 -0600 Subject: [PATCH] Added help; removed -P option --- README.txt | 1 - farend.sh | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.txt b/README.txt index 5d8b836..91af995 100644 --- a/README.txt +++ b/README.txt @@ -33,7 +33,6 @@ USAGE -l $LIMIT | The amount of days you'd like to print events in advance (7) -d $DIVIDER | Set the divider string under headers (default is 40 "-" chars) -T $TODAY_MSG | Set the header title for today's events ("TODAY") --P $PAST_MSG | Set the header title for events already past ("LONG GONE") -L $LATER_MSG | Set the header title to non-today upcoming events ("NEXT") -q | Print upcoming events without dividers or headers ($*_MSG) -h | Print the help message diff --git a/farend.sh b/farend.sh index 5fbaa93..35803e7 100755 --- a/farend.sh +++ b/farend.sh @@ -194,7 +194,7 @@ function is_balanced_date { if test "$month" -gt 12; then return 1 elif test "$day" -gt "$month_max" ; then - return 1 + return 1 else return 0 fi @@ -204,7 +204,8 @@ function is_balanced_date { function carry_date { local date="$1" - while test "$(is_balanced_date "$date")" -eq 1; do + is_balanced_date "$date" + while test "$?" -eq 1; do date="$(carry_months "$(carry_days "$date")")" done echo "$date" @@ -218,9 +219,10 @@ function carry_days { local days="$(date_day "$date")" if test "$days" -gt "$(month_days "$month")"; then - local new_days="$(subtract "$days" - "$(month_days "$month")" | digits 2)" + local new_days="$(subtract "$days" "$(month_days "$month")")" local new_month="$(add "$month" "1")" + new_days="$(echo "$new_days" | digits 2)" + new_month="$(echo "$new_month" | digits 2)" echo "${year}-${new_month}-${new_days}" else echo "$date" @@ -321,6 +323,13 @@ function generate_report { # -------------------------------------- # INVOCATION +BIN="$(echo "$0" | sed 's%.*/%%')" +function print_help { + echo "usage: $BIN [-hq] [-l \$LIMIT] [-L | -D \$MSG] [\$TODO_PATH]" + exit 2 +} + + # ------------------ # OPTIONS @@ -332,15 +341,14 @@ LATER_MSG="NEXT EPISODE..." PAST_MSG="FROM THE GRAVE" QUIET_MODE=1 -while getopts 'l:D:T:L:P:qh' c; do +while getopts 'l:D:T:L:qh' c; do case "$c" in l) LIMIT="$OPTARG" ;; D) DIVIDER="$OPTARG" ;; T) TODAY_MSG="$OPTARG" ;; L) LATER_MSG="$OPTARG" ;; - P) PAST_MSG="$OPTARG" ;; q) QUIET_MODE=0 ;; - h) echo "$HELP"; exit 2 ;; + h) print_help ;; esac done shift "$(dec "$OPTIND" 1)"