dots/.bin/check-battery-level

21 lines
469 B
Plaintext
Raw Normal View History

2020-04-09 17:08:28 +02:00
#!/usr/bin/env bash
2020-09-11 20:16:57 +02:00
RED="\033[0;31m"
GREEN="\033[0;32m"
NC="\033[0m"
2020-04-09 17:08:28 +02:00
capacityStatus=$(cat /sys/class/power_supply/BAT0/capacity)
2020-09-06 18:15:51 +02:00
chargingStatus=""
if [ -f /sys/class/power_supply/AC/online ]; then
chargingStatus=$(cat /sys/class/power_supply/AC/online)
fi
2020-04-09 17:08:28 +02:00
if [ "$chargingStatus" == "1" ]; then
printf "Battery is ${GREEN}charging${NC}.\n"
elif [ "$chargingStatus" == "0" ]; then
printf "Battery is ${RED}discharging${NC}.\n"
fi
printf "$capacityStatus%% \n"