X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=.bin%2Fredshift-check;h=b90eadb0c4b23b2896e0ab856b1e7e3aec9ac839;hb=853a0c1f76ed7cb7e9bd6619b9e58b38cca1a1f0;hp=eeaf8a7530b128006137067470e28ede8ec954b8;hpb=e5affb5220d89e603dcc033a89f31197aa1d9232;p=home.git diff --git a/.bin/redshift-check b/.bin/redshift-check index eeaf8a7..b90eadb 100755 --- a/.bin/redshift-check +++ b/.bin/redshift-check @@ -1,8 +1,68 @@ -#!/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 + + local auth="${HOME}/.Xauthority" + if [[ -e ${auth} ]]; then + export XAUTHORITY=${auth} + fi + + 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 + local min=2000 + temps=( + [20]=$(( min + 2000 )) + [21]=$(( min + 1500 )) + [22]=$(( min + 1000 )) + [23]=$(( min + 500 )) + [00]=$(( min )) + [01]=$(( min )) + [02]=$(( min )) + [03]=$(( min )) + [04]=$(( min )) + [05]=$(( min )) + [06]=$(( min + 500 )) + [07]=$(( min + 1000 )) + [08]=$(( min + 1500 )) + [09]=$(( min + 2000 )) + ) + + t=${temps[${h}]} + if [[ -z ${t} ]]; then + rs -x + else + rs -O ${t}k + fi +} +main "$@"