Browse code

Added help; removed -P option

Jaidyn Levesque authored on 2020-01-26 06:35:33
Showing 2 changed files
... ...
@@ -33,7 +33,6 @@ USAGE
33 33
 -l $LIMIT      | The amount of days you'd like to print events in advance (7)
34 34
 -d $DIVIDER    | Set the divider string under headers (default is 40 "-" chars)
35 35
 -T $TODAY_MSG  | Set the header title for today's events ("TODAY")
36
--P $PAST_MSG   | Set the header title for events already past ("LONG GONE")
37 36
 -L $LATER_MSG  | Set the header title to non-today upcoming events  ("NEXT")
38 37
 -q             | Print upcoming events without dividers or headers ($*_MSG)
39 38
 -h             | Print the help message
... ...
@@ -194,7 +194,7 @@ function is_balanced_date {
194 194
 	if test "$month" -gt 12; then
195 195
 		return 1
196 196
 	elif test "$day" -gt "$month_max" ; then
197
-    		return 1
197
+		return 1
198 198
 	else
199 199
 		return 0
200 200
 	fi
... ...
@@ -204,7 +204,8 @@ function is_balanced_date {
204 204
 function carry_date {
205 205
 	local date="$1"
206 206
 
207
-	while test "$(is_balanced_date "$date")" -eq 1; do
207
+	is_balanced_date "$date"
208
+	while test "$?" -eq 1; do
208 209
 		date="$(carry_months "$(carry_days "$date")")"
209 210
 	done
210 211
 	echo "$date"
... ...
@@ -218,9 +219,10 @@ function carry_days {
218 219
 	local days="$(date_day "$date")"
219 220
 
220 221
 	if test "$days" -gt "$(month_days "$month")"; then
221
-		local new_days="$(subtract "$days"
222
-		                           "$(month_days "$month")" | digits 2)"
222
+		local new_days="$(subtract "$days" "$(month_days "$month")")"
223 223
 		local new_month="$(add "$month" "1")"
224
+		new_days="$(echo "$new_days" | digits 2)"
225
+		new_month="$(echo "$new_month" | digits 2)"
224 226
 		echo "${year}-${new_month}-${new_days}"
225 227
 	else
226 228
 		echo "$date"
... ...
@@ -321,6 +323,13 @@ function generate_report {
321 323
 # --------------------------------------
322 324
 # INVOCATION
323 325
 
326
+BIN="$(echo "$0" | sed 's%.*/%%')"
327
+function print_help {
328
+	echo "usage: $BIN [-hq] [-l \$LIMIT] [-L | -D \$MSG] [\$TODO_PATH]"
329
+	exit 2
330
+}
331
+
332
+
324 333
 # ------------------
325 334
 # OPTIONS
326 335
 
... ...
@@ -332,15 +341,14 @@ LATER_MSG="NEXT EPISODE..."
332 341
 PAST_MSG="FROM THE GRAVE"
333 342
 QUIET_MODE=1
334 343
 
335
-while getopts 'l:D:T:L:P:qh' c; do
344
+while getopts 'l:D:T:L:qh' c; do
336 345
 	case "$c" in
337 346
 			l) LIMIT="$OPTARG" ;;
338 347
 			D) DIVIDER="$OPTARG" ;;
339 348
 			T) TODAY_MSG="$OPTARG" ;;
340 349
 			L) LATER_MSG="$OPTARG" ;;
341
-			P) PAST_MSG="$OPTARG" ;;
342 350
 			q) QUIET_MODE=0 ;;
343
-			h) echo "$HELP"; exit 2 ;;
351
+			h) print_help ;;
344 352
 	esac
345 353
 done
346 354
 shift "$(dec "$OPTIND" 1)"