24 lines
557 B
Bash
Executable file
24 lines
557 B
Bash
Executable file
#!/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
|