dotfiles/_suckless/_scripts/sb-battery
2021-07-26 15:56:06 +02:00

18 lines
614 B
Bash
Executable File

#!/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="\uea0b" ;;
"Discharging") status="\ue1a5" ;;
"Charging") status="\ue63c" ;;
"Not charging") status="\ue1a6" ;;
"Unknown") status="\ue1a3" ;;
esac
capacity=$(cat "$battery/capacity")
# Will make a warn variable if discharging and low
[ "$capacity" -le 20 ] && printf "\ue19c ^c#161616^^b#fd4285^${capacity}%%^d^" || printf "${status} ${capacity}%%"
done && exit 0