commit 8f59a571231a02d1e9e0b44d44384cfb17d379f0
parent db862493b60ae85808d2e477ce953db1c4c47eeb
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Thu, 10 Sep 2020 10:40:26 -0700
Simplify and reformat
usage message shortened to just a synopsys.
h option removed.
more verbosity on invalid arguments.
options sorted alphabeticaly.
Diffstat:
1 file changed, 8 insertions(+), 15 deletions(-)
diff --git a/scripts/.local/bin/now b/scripts/.local/bin/now
@@ -1,26 +1,19 @@
#!/usr/bin/env dash
-# print the current date, time, or both.
+# display the date, time, or both
set -eu
-# date and time formats
+# strftime(3):
date="%Y%m%d"
time="%H%M%S"
-# display usage
-usage()
-{
- echo "usage, `basename $0` [-fdt]"
- echo "\t-f, display date and time"
- echo "\t-d, display date"
- echo "\t-t, display time"
- echo "\t-h, display help and exit"
-}
+usage() { echo "usage: `basename $0` [-dft]" ;}
+err() { echo "`basename $0`: $@" 1>&2 ;}
-case ${1:-"-f"} in
- -f) date +$date-$time;;
+case "${1:-"-f"}"
+in
-d) date +$date;;
+ -f) date +$date-$time;;
-t) date +$time;;
- -h) usage; exit;;
- *) echo "error: invalid argument" 1>&2; return 1;;
+ *) err "'$1': unknown option."; usage; exit 1;;
esac