]> git.donarmstrong.com Git - bin.git/blob - intel_brightness
use notify-send if it is installed when timers expire
[bin.git] / intel_brightness
1 #!/bin/bash
2
3 if [ "$(id -u)" != "0" ]; then
4     exec sudo "$0" "$@"
5 fi;
6
7 MAX=$(cat /sys/class/backlight/intel_backlight/max_brightness)
8 CURRENT=$(cat /sys/class/backlight/intel_backlight/brightness)
9 NEW=$CURRENT
10 ADJ=$(( $MAX  / ${2:-20} ))
11
12 if [ "$1" == "max" ]; then
13     NEW=$MAX
14 elif [ "$1" == "off" ]; then
15     NEW=0
16 elif [ "$1" == "min" ]; then
17     NEW=1
18 elif [ "$1" == "dec" ]; then
19     NEW=$(( $CURRENT - $ADJ  < 1 ? 1 : $CURRENT - $ADJ ))
20 elif echo "$1" | grep -q '^[[:digit:]][[:digit:]]*\%*$'; then
21     NEW=$(( $(echo "$1" | sed 's/\%//') * $MAX / 100 ))
22 else
23     NEW=$(( $CURRENT + $ADJ  >= $MAX ? $MAX : $CURRENT + $ADJ ))
24 fi
25
26 echo $NEW > /sys/class/backlight/intel_backlight/brightness