#!/bin/bash
-cd
-export DISPLAY=:0
-
-case $1 in
---reset) exec redshift -x ;;
-esac
-
-h=$(date +%H)
-
-declare -A temps
-temps=(
- [20]=5000
- [21]=4500
- [22]=4000
- [23]=3500
- [00]=3000
- [01]=3000
- [02]=3000
- [03]=3000
- [04]=3000
- [05]=3000
- [06]=3500
- [07]=4000
- [08]=4500
- [09]=5000
-)
-
-t=${temps[${h}]}
-if [[ -z ${t} ]]; then
- exec redshift -x
-else
- exec redshift -O ${t}k
-fi
+
+usage() {
+ cat <<-EOF
+ Usage: ${0##*/} [options]
+
+ Options:
+ --reset reset display to no redshift
+ EOF
+
+ if [[ $# -eq 0 ]] ; then
+ exit 0
+ else
+ printf '\nERROR: %s\n' "$*" >&2
+ exit 1
+ fi
+}
+
+main() {
+ cd
+ export DISPLAY=:0
+
+ while [[ $# -gt 0 ]] ; do
+ case $1 in
+ --reset) exec redshift -x ;;
+ -h|--help) usage ;;
+ *) usage "Unknown option: $1" ;;
+ esac
+ done
+
+ h=$(date +%H)
+
+ declare -A temps
+ temps=(
+ [20]=5000
+ [21]=4500
+ [22]=4000
+ [23]=3500
+ [00]=3000
+ [01]=3000
+ [02]=3000
+ [03]=3000
+ [04]=3000
+ [05]=3000
+ [06]=3500
+ [07]=4000
+ [08]=4500
+ [09]=5000
+ )
+
+ t=${temps[${h}]}
+ if [[ -z ${t} ]]; then
+ exec redshift -x
+ else
+ exec redshift -O ${t}k
+ fi
+}
+main "$@"