]> git.wh0rd.org - home.git/blobdiff - .bin/redshift-check
le-renew: switch to cryptography module
[home.git] / .bin / redshift-check
index a74940625eb7b9a873313b817fd8c52638ace259..9481c09d8a4fe0fbb059f173df666d9cd85c56c1 100755 (executable)
@@ -1,8 +1,62 @@
-#!/bin/sh
-h=$(date +%H)
-if [ ${h#0} -lt 10 -o ${h#0} -ge 21 ]; then
-       (pgrep -f /usr/bin/redshift >/dev/null 2>&1 || DISPLAY=:0 exec /usr/bin/redshift -l 42:-71) &
-else
-       killall -q redshift
-fi
-:
+#!/bin/bash
+
+usage() {
+       cat <<-EOF
+       Usage: ${0##*/} [options]
+
+       Options:
+         -x, --reset    reset display to no redshift
+       EOF
+
+       if [[ $# -eq 0 ]] ; then
+               exit 0
+       else
+               printf '\nERROR: %s\n' "$*" >&2
+               exit 1
+       fi
+}
+
+rs() {
+       exec redshift -m randr "$@"
+}
+
+main() {
+       cd /
+       export DISPLAY=:0
+
+       while [[ $# -gt 0 ]] ; do
+               case $1 in
+               -x|--reset) rs -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
+               rs -x
+       else
+               rs -O ${t}k
+       fi
+}
+main "$@"