dotfiles/scripts/oled-brightness
2022-12-12 12:30:43 -05:00

33 lines
619 B
Bash
Executable File

#!/bin/sh
BR_DIR="/sys/class/backlight/intel_backlight/"
test -d "$BR_DIR" || exit 0
MIN=0
MAX=$(cat "$BR_DIR/max_brightness")
VAL=$(cat "$BR_DIR/brightness")
if [ "$1" = down ]; then
VAL=$((VAL-4096))
else
VAL=$((VAL+4096))
fi
if [ "$VAL" -lt $MIN ]; then
VAL=$MIN
elif [ "$VAL" -gt $MAX ]; then
VAL=$MAX
fi
PERCENT=`echo "$VAL / $MAX" | bc -l`
export XAUTHORITY=$HOME/.Xauthority # CHANGE "ivo" TO YOUR USER
export DISPLAY=:0
echo "xrandr --output eDP-1 --brightness $PERCENT" > /tmp/oled-brightness.log
xrandr --output eDP-1 --brightness $PERCENT
echo $VAL | sudo tee "$BR_DIR/brightness"