dotfiles/_linux/_gui/_scripts/sb-battery

18 lines
657 B
Plaintext
Raw Permalink Normal View History

2023-10-23 22:32:24 +02:00
#!/bin/bash
for battery in /sys/class/power_supply/BAT?*; do
# If non-first battery, print a space separator.
[ -n "${capacity+x}" ] && printf " "
# Sets up the status and capacity
case "$(cat "$battery/status")" in
"Full") status="\uf102" ;;
2024-01-22 13:22:15 +01:00
"Discharging") status="\uf063" ;;
"Charging") status="\uf062" ;;
2023-10-23 22:32:24 +02:00
"Not charging") status="\uf444"; exit 0 ;;
"Unknown") status="\uf128" ;;
esac
capacity=$(cat "$battery/capacity")
# Will make a warn variable if discharging and low
[ "$capacity" -le 20 ] && printf "<span background='#770000' foreground='#ffffff'>${status} ${capacity}%%</span>" || printf "${status} ${capacity}%%"
2023-10-23 22:32:24 +02:00
done && exit 0