]> git.wh0rd.org Git - home.git/commitdiff
redshift: clean up a bit
authorMike Frysinger <vapier@gentoo.org>
Wed, 12 Nov 2014 23:56:43 +0000 (15:56 -0800)
committerMike Frysinger <vapier@gentoo.org>
Wed, 12 Nov 2014 23:56:43 +0000 (15:56 -0800)
.bin/redshift-check

index c994ad087d0fdd51fd5ef3aa497e98537cb46145..4cf84a39a874c5233e12481f13c698f6ef76d0da 100755 (executable)
@@ -1,34 +1,58 @@
 #!/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 "$@"