#!/usr/bin/env bash # Graphics card CARD=`ls /sys/class/backlight | head -n 1` # Get brightness get_backlight() { if [[ "$CARD" == *"intel_"* ]]; then BNESS=`xbacklight -get` LIGHT=${BNESS%.*} else LIGHT=$(printf "%.0f\n" `light -G`) fi echo "${LIGHT}%" } # Get icons get_icon() { backlight="$(get_backlight)" current="${backlight%%%}" if [[ ("$current" -ge "0") && ("$current" -le "20") ]]; then icon='/usr/share/icons/dunst/brightness-20.png' elif [[ ("$current" -ge "20") && ("$current" -le "40") ]]; then icon='/usr/share/icons/dunst/brightness-40.png' elif [[ ("$current" -ge "40") && ("$current" -le "60") ]]; then icon='/usr/share/icons/dunst/brightness-60.png' elif [[ ("$current" -ge "60") && ("$current" -le "80") ]]; then icon='/usr/share/icons/dunst/brightness-80.png' elif [[ ("$current" -ge "80") && ("$current" -le "100") ]]; then icon='/usr/share/icons/dunst/brightness-100.png' fi } # Increase brightness inc_backlight() { if [[ "$CARD" == *"intel_"* ]]; then xbacklight -inc 10 && get_icon && dunstify -u low --replace=69 -i "$icon" "Brightness : $(get_backlight)" else light -A 5 && get_icon && dunstify -u low --replace=69 -i "$icon" "Brightness : $(get_backlight)" fi } # Decrease brightness dec_backlight() { if [[ "$CARD" == *"intel_"* ]]; then xbacklight -dec 10 && get_icon && dunstify -u low --replace=69 -i "$icon" "Brightness : $(get_backlight)" else light -U 5 && get_icon && dunstify -u low --replace=69 -i "$icon" "Brightness : $(get_backlight)" fi } # Execute accordingly if [[ "$1" == "--get" ]]; then get_backlight elif [[ "$1" == "--inc" ]]; then inc_backlight elif [[ "$1" == "--dec" ]]; then dec_backlight else get_backlight fi