backlight.sh 1002 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/sh
  2. backlight_change(){
  3. if echo "$1" | grep -E "^\+|([Ii](ncrease)?)$"; then
  4. xbacklight "+$2"
  5. elif echo "$1" | grep -E "^\-|([Dd](ecrease)?)$"; then
  6. xbacklight "-$2"
  7. elif echo "$1" | grep -E "^\=|([Ss](et)?)$"; then
  8. xbacklight "=$2"
  9. else
  10. echo -a "$3" -h string:x-dunst-stack-tag:BACKLIGHT "Backlight" "Invalid backlight command"
  11. fi
  12. level="$(xbacklight -get | grep -Eo '^[0-9]+')"
  13. dunstify -a "$3" -h string:x-dunst-stack-tag:BACKLIGHT "Backlight" -h int:value:"$level" "$level"
  14. }
  15. current=$(xbacklight -get | grep -Eo '^[0-9]+')
  16. if [ -z "$current" ]; then
  17. dunstify -a "$1" -h string:x-dunst-stack-tag:BACKLIGHT "Backlight" "Backlight not supported in this system"
  18. return 1
  19. elif [ "$current" -gt 50 ]; then
  20. backlight_change "$2" 10 "$1"
  21. elif [ "$current" -gt 25 ]; then "$1"
  22. backlight_change "$2" 5 "$1"
  23. elif [ "$current" -gt 10 ]; then
  24. backlight_change "$2" 2 "$1"
  25. elif [ "$current" -gt 1 ]; then
  26. backlight_change "$2" "0.5" "$1"
  27. else
  28. backlight_change "$2" "0.1" "$1"
  29. fi