rice/dots/.config/sway/status_command

25 lines
557 B
Text
Raw Normal View History

2023-09-02 19:47:37 +00:00
#!/bin/sh
while :; do
energy_full=0
energy_now=0
charging=
for bat in /sys/class/power_supply/*/capacity; do
bat="${bat%/*}"
read -r full <"$bat/energy_full"
read -r now <"$bat/energy_now"
energy_full=$((energy_full + full))
energy_now=$((energy_now + now))
done
if cat /sys/class/power_supply/*/status | grep -q Charging; then
charging=+
fi
percentage=$((energy_now * 100 / energy_full))
printf '%s %s ' "$charging$percentage%" "$(date +'%H:%M:%S')"
sleep 1
done