]> git.wh0rd.org Git - home.git/blob - .bin/redshift-check
PS1: shorten slightly & add PS0 recovery
[home.git] / .bin / redshift-check
1 #!/bin/bash
2
3 usage() {
4         cat <<-EOF
5         Usage: ${0##*/} [options]
6
7         Options:
8           -x, --reset    reset display to no redshift
9         EOF
10
11         if [[ $# -eq 0 ]] ; then
12                 exit 0
13         else
14                 printf '\nERROR: %s\n' "$*" >&2
15                 exit 1
16         fi
17 }
18
19 rs() {
20         exec redshift -m randr "$@"
21 }
22
23 main() {
24         cd /
25         export DISPLAY=:0
26
27         local auth="${HOME}/.Xauthority"
28         if [[ -e ${auth} ]]; then
29                 export XAUTHORITY=${auth}
30         fi
31
32         while [[ $# -gt 0 ]] ; do
33                 case $1 in
34                 -x|--reset) rs -x ;;
35                 -h|--help) usage ;;
36                 *) usage "Unknown option: $1" ;;
37                 esac
38         done
39
40         h=$(date +%H)
41
42         declare -A temps
43         local min=2000
44         temps=(
45                 [20]=$(( min + 2000 ))
46                 [21]=$(( min + 1500 ))
47                 [22]=$(( min + 1000 ))
48                 [23]=$(( min + 500 ))
49                 [00]=$(( min ))
50                 [01]=$(( min ))
51                 [02]=$(( min ))
52                 [03]=$(( min ))
53                 [04]=$(( min ))
54                 [05]=$(( min ))
55                 [06]=$(( min + 500 ))
56                 [07]=$(( min + 1000 ))
57                 [08]=$(( min + 1500 ))
58                 [09]=$(( min + 2000 ))
59         )
60
61         t=${temps[${h}]}
62         if [[ -z ${t} ]]; then
63                 rs -x
64         else
65                 rs -O ${t}k
66         fi
67 }
68 main "$@"