aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRatakor <ratakor@disroot.org>2023-04-04 22:07:59 +0200
committerRatakor <ratakor@disroot.org>2023-04-04 22:07:59 +0200
commit6abe537aadab92bd9f6fdc97116c4add14b8a67c (patch)
tree83019adba02dc0449b99b6b167518b2aa05e3c6b
parent4463872d59fecb763b579bfd59d454ecfd6d2851 (diff)
handle multiple args0.4
-rw-r--r--Makefile2
-rw-r--r--README.md3
-rwxr-xr-xquand53
3 files changed, 37 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index fc9693f..5d02956 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
.POSIX:
-VERSION = 0.3
+VERSION = 0.4
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
diff --git a/README.md b/README.md
index 944f180..12ca92f 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ The comma is not necessary, I just like it.
# For events that happen once a week:
# The name of each day depends on your locale
-Mon, don't forget to update with pacman -Syyu
+Mon, don't forget to update with emerge -uDN @world
Fri, it's friday!
# Use a star for events that happen once a year:
@@ -63,4 +63,3 @@ mondayfirst=0
## TODO
- add a ICS file converter or handle ICS files
- add a man page
-- handle multiple arguments
diff --git a/quand b/quand
index 9cbeb5b..0fe64de 100755
--- a/quand
+++ b/quand
@@ -1,6 +1,7 @@
#!/bin/sh
+# shellcheck disable=SC2046
-VERSION="0.3"
+VERSION="0.4"
CONF="${XDG_CONFIG_HOME:-$HOME/.config}/quand/config"
language="${LANG:-en_US.UTF-8}"
@@ -64,6 +65,35 @@ calendar() {
fi
}
+args() {
+ while [ -n "$*" ]; do
+ case $1 in
+ -c|--calendar)
+ [ -z "$2" ] &&
+ printf 'Error: no argument given\n' 1>&2 &&
+ exit 1
+ calendar="$2" ;;
+ -p|--past)
+ [ -z "$2" ] &&
+ printf 'Error: no argument given\n' 1>&2 &&
+ exit 1
+ [ "$2" -gt 0 ] &&
+ printf "\033[33mHint:\033[m 'past' is negative.\n\n"
+ past="$2" ;;
+ -f|--future)
+ [ -z "$2" ] &&
+ printf 'Error: no argument given\n' 1>&2 &&
+ exit 1
+ future="$2" ;;
+ *)
+ printf 'Error: unknown option %s\n' "$*" 1>&2
+ usage
+ exit 1 ;;
+ esac
+ shift 2
+ done
+}
+
usage() {
printf 'Usage: %s [options]
@@ -71,6 +101,7 @@ Options:
no option | Default
-h|--help │ Print this help message and exit
-v|--version | Print the version
+-c|--calendar [path] | Temporarily change the calendar file used
-p|--past [n] | Temporarily change past (n is negative)
-f|--future [n] | Temporarily change future (n is positive)
|
@@ -87,7 +118,7 @@ main() {
case $1 in
-v|--version)
printf '%s %s\n' "${0##*/}" "$VERSION" 1>&2
- return 0 ;;
+ return 0 ;;
-h|--help)
usage
return 0 ;;
@@ -97,17 +128,8 @@ main() {
c|cal)
calendar "$2"
return ;;
- -p|--past)
- [ -z "$2" ] &&
- printf 'Error: no argument given\n' 1>&2 &&
- return 1
- past="$2"
- exec ;;
- -f|--future)
- [ -z "$2" ] &&
- printf 'Error: no argument given\n' 1>&2 &&
- return 1
- future="$2"
+ -*)
+ args "$@"
exec ;;
'')
exec ;;
@@ -127,23 +149,18 @@ main() {
[ "$header" = 1 ] && printf '%s\n\n' "$(LC_ALL="$language" date)"
while [ "$past" -lt -1 ]; do
- # shellcheck disable=SC2046
print $(split "$(getdate "$past")")
past=$((past+1))
done
- # shellcheck disable=SC2046
[ "$past" -eq -1 ] && print $(split "$(getdate "-1")") "$yesterday"
- # shellcheck disable=SC2046
print $(split "$(getdate 0)") "$today"
- # shellcheck disable=SC2046
[ "$future" -ge 1 ] && print $(split "$(getdate "+1")") "$tomorrow"
cpt=2
while [ "$future" -gt 1 ]; do
- # shellcheck disable=SC2046
print $(split "$(getdate "+$cpt")")
future="$((future-1))"
cpt="$((cpt+1))"