brightness.sh 988 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env bash
  2. current_rel() {
  3. brightnessctl i | grep -Po "(?<=\().*?(?=\%)"
  4. }
  5. max=$(brightnessctl m)
  6. factor=3
  7. brightness_step=$((max * factor / 100 < 1 ? 1 : max * factor / 100))
  8. icon_low="notification-display-brightness-low"
  9. icon_high="notification-display-brightness-full"
  10. current_abs=$(brightnessctl g)
  11. case $1'' in
  12. '') ;;
  13. 'down')
  14. # if current value <= 3% and absolute value != 1, set brightness to absolute 1
  15. if [ "$current_abs" -le "$((factor * max / 100))" ] && [ "$current_abs" -gt 0 ] && [ "$current_abs" -ne 1 ]; then
  16. brightnessctl s 1
  17. icon=$icon_low
  18. else
  19. brightnessctl s $(("$current_abs" - "$brightness_step"))
  20. icon=$icon_low
  21. fi
  22. ;;
  23. 'up')
  24. brightnessctl s $(("$current_abs" + "$brightness_step"))
  25. icon=$icon_high
  26. ;;
  27. esac
  28. brightness_percentage=$(current_rel)
  29. notify-send -i "$icon" "Brightness Level" "Backlight is at $brightness_percentage%"