2023-06-27 10:13:14 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# @requires: brightnessctl
|
|
|
|
|
|
|
|
percentage () {
|
|
|
|
local val=$(echo $1 | tr '%' ' ' | awk '{print $1}')
|
|
|
|
local icon1=$2
|
|
|
|
local icon2=$3
|
|
|
|
local icon3=$4
|
|
|
|
local icon4=$5
|
2023-07-30 22:15:44 -04:00
|
|
|
local icon5=$6
|
|
|
|
local icon6=$7
|
|
|
|
local icon7=$8
|
|
|
|
local icon8=$9
|
|
|
|
if [ "$val" -le 1 ]; then
|
|
|
|
echo "$icon1"
|
|
|
|
elif [ "$val" -le 15 ]; then
|
|
|
|
echo "$icon2"
|
2023-06-27 10:13:14 -04:00
|
|
|
elif [ "$val" -le 30 ]; then
|
2023-07-30 22:15:44 -04:00
|
|
|
echo "$icon3"
|
|
|
|
elif [ "$val" -le 45 ]; then
|
|
|
|
echo "$icon4"
|
2023-06-27 10:13:14 -04:00
|
|
|
elif [ "$val" -le 60 ]; then
|
2023-07-30 22:15:44 -04:00
|
|
|
echo "$icon5"
|
|
|
|
elif [ "$val" -le 75 ]; then
|
|
|
|
echo "$icon6"
|
|
|
|
elif [ "$val" -le 90 ]; then
|
|
|
|
echo "$icon7"
|
2023-06-27 10:13:14 -04:00
|
|
|
else
|
2023-07-30 22:15:44 -04:00
|
|
|
echo "$icon8"
|
2023-06-27 10:13:14 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-07-30 22:15:44 -04:00
|
|
|
|
2023-06-27 10:13:14 -04:00
|
|
|
get_brightness () {
|
|
|
|
(( br = $(brightnessctl get) * 100 / $(brightnessctl max) ))
|
|
|
|
echo $br
|
|
|
|
}
|
|
|
|
|
|
|
|
get_percent () {
|
|
|
|
echo $(get_brightness)%
|
|
|
|
}
|
|
|
|
|
|
|
|
get_icon () {
|
|
|
|
local br=$(get_percent)
|
2023-07-30 22:15:44 -04:00
|
|
|
echo $(percentage "$br" " " " " " " " " " " " " " " " ")
|
2023-06-27 10:13:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $1 == "br" ]]; then
|
|
|
|
get_brightness
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $1 == "percent" ]]; then
|
|
|
|
get_percent
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $1 == "icon" ]]; then
|
2023-07-30 22:15:44 -04:00
|
|
|
while true; do
|
|
|
|
sleep 0.2
|
|
|
|
get_icon
|
|
|
|
done
|
2023-06-27 10:13:14 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $1 == "set" ]]; then
|
|
|
|
brightnessctl set $2%
|
|
|
|
fi
|