1
0
Fork 0
dotfiles/files/.local/bin/brightness-control

42 lines
1.1 KiB
Plaintext
Raw Normal View History

2018-10-31 17:11:04 +00:00
#!/usr/bin/env bash
# You can call this script like this:
# $ ./brightnessControl.sh up
# $ ./brightnessControl.sh down
# Script inspired by these wonderful people:
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a
function get_brightness {
brightnessctl -m | grep -o '[0-9]\+%' | head -c-2
}
function send_notification {
icon="notification-display-brightness"
brightness=$(get_brightness)
# Make the bar with the special character ─ (it's not dash -)
# https://en.wikipedia.org/wiki/Box-drawing_character
bar=$(seq -s "━" 0 $((brightness / 2)) | sed 's/[0-9]//g')
# Send the notification
dunstify -i "$icon" -r 5555 -u normal " $bar"
}
case $1 in
up)
# increase the backlight by 5%
brightnessctl set +5%
send_notification
;;
down)
2018-10-31 18:04:38 +00:00
if [[ $(get_brightness) -lt 5 ]]; then
# avoid 0% brightness
brightnessctl set 1%
else
# decrease the backlight by 5%
brightnessctl set 5%-
fi
2018-10-31 17:11:04 +00:00
send_notification
;;
esac