From 9d483f81a9022a007350e7f1bd4b7da90965748f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 12 Nov 2014 15:56:43 -0800 Subject: [PATCH] redshift: clean up a bit --- .bin/redshift-check | 90 ++++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/.bin/redshift-check b/.bin/redshift-check index c994ad0..4cf84a3 100755 --- a/.bin/redshift-check +++ b/.bin/redshift-check @@ -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 "$@" -- 2.39.2