dotfiles/dot_config/sway/brightness.sh

55 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# You can call this script like this:
# $./brightness.sh up
# $./brightness.sh down
# Based on sebastiencs' script (https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a)
timeout=1000
function get_brightness {
echo $(($(brightnessctl get) * 100 / $(brightnessctl max)))
}
function send_notification {
brightness=$(get_brightness)
# Make the bar with the special character (it's not dash -) Make sure it's not replaced by '?'
# https://en.wikipedia.org/wiki/Box-drawing_character
bar=$(seq -s "─" $(($brightness / 5)) | sed 's/[0-9]//g')
sicon=low-brightness
if ((brightness >= 50)); then
sicon=display-brightness-high-symbolic
icon=
elif ((brightness >= 24)); then
sicon=display-brightness-medium-symbolic
icon=
elif ((brightness >= 10)); then
sicon=display-brightness-low-symbolic
icon=
else
sicon=display-brightness-off-symbolic
icon=
fi
#Send the notification
notify-send -e -i $sicon -r 2593 -t $timeout -u low "$icon $brightness $bar"
}
case $1 in
up)
new=$(get_brightness | awk '{ print int(($1 + .72) * 1.4) }')
;;
down)
new=$(get_brightness | awk '{ print int($1 / 1.4) }')
;;
*)
new=$1
;;
esac
[[ $new -ge 5 ]] && brightnessctl set $new"%"
send_notification