Skip to content

Instantly share code, notes, and snippets.

@tildejustin
Last active November 17, 2023 13:02
Show Gist options
  • Save tildejustin/5eb8b16cd45be83bf58c8a02020e4133 to your computer and use it in GitHub Desktop.
Save tildejustin/5eb8b16cd45be83bf58c8a02020e4133 to your computer and use it in GitHub Desktop.
note to self: in /usr/local/bin
#!/bin/bash
curr_brightness=$(cat /sys/class/backlight/intel_backlight/brightness)
curr_brightness=$(($curr_brightness))
max_brightness="$(cat /sys/class/backlight/intel_backlight/max_brightness)"
max_brightness=$(($max_brightness))
brightness=0
# -10%: decrease by a percentage, not going below 0
# +10%: increase by a percentage, not going above $max_brightness
# 10%: set to an absolute percentage between 0 and $max_brightness
# 10: set to an absoulte brightness not exceeding #max_brightness
case $1 in
incp)
brightness=$(($curr_brightness + $max_brightness * $2 / 100))
;;
inc)
brightness=$(($curr_brightness + $2))
;;
setp)
brightness=$(($max_brightness * $2 / 100))
;;
"set")
brightness=$(($2))
;;
esac
((brightness = $brightness > $max_brightness ? $max_brightness : $brightness))
((brightness = $brightness < 1 ? 1 : $brightness))
echo "$curr_brightness -> $brightness"
echo $brightness > /sys/class/backlight/intel_backlight/brightness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment