get battery percentage script updated

This commit is contained in:
wt committed 2024-07-14 18:07:18 +07:00
1 parent d4aa3da4c0
commit 41cc6db737
1 file changed
+20 -11
+20 -11
View File
@@ -5,19 +5,28 @@ Color_off='\033[0m'
Red='\033[0;31m' Red='\033[0;31m'
Yellow='\033[1;33m' Yellow='\033[1;33m'
batfull=$(cat /sys/class/power_supply/$1/energy_full) batteries=$(ls /sys/class/power_supply/ | grep BAT)
batnow=$(cat /sys/class/power_supply/$1/energy_now)
batperc=$((($batnow/($batfull/100))))
if [[ "$batperc" -le "20" ]]; then if [[ "$batteries" == "" ]]; then
printf "$Red$batperc$Color_off\n" printf "$Yellow**$Red error:$Color_off no battery found\n"
exit 0 exit 1;
fi fi
if [[ "$batperc" -le "70" ]]; then for i in $batteries; do
printf "$Yellow$batperc$Color_off\n" batfull=$(cat /sys/class/power_supply/$i/energy_full)
exit 0 batnow=$(cat /sys/class/power_supply/$i/energy_now)
fi batperc=$((($batnow/($batfull/100))))
printf "$Green$batperc$Color_off\n" if [[ "$batperc" -le "20" ]]; then
printf "$Yellow**$Color_off $i: $Red$batperc$Color_off\n"
exit 0
fi
if [[ "$batperc" -le "70" ]]; then
printf "$Yellow**$Color_off $i: $Yellow$batperc$Color_off\n"
exit 0
fi
printf "$Yellow**$Color_off $i: $Green$batperc$Color_off\n"
done