get battery percentage script updated
This commit is contained in:
+20
-11
@@ -5,19 +5,28 @@ Color_off='\033[0m'
|
||||
Red='\033[0;31m'
|
||||
Yellow='\033[1;33m'
|
||||
|
||||
batfull=$(cat /sys/class/power_supply/$1/energy_full)
|
||||
batnow=$(cat /sys/class/power_supply/$1/energy_now)
|
||||
batperc=$((($batnow/($batfull/100))))
|
||||
batteries=$(ls /sys/class/power_supply/ | grep BAT)
|
||||
|
||||
if [[ "$batperc" -le "20" ]]; then
|
||||
printf "$Red$batperc$Color_off\n"
|
||||
exit 0
|
||||
if [[ "$batteries" == "" ]]; then
|
||||
printf "$Yellow**$Red error:$Color_off no battery found\n"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [[ "$batperc" -le "70" ]]; then
|
||||
printf "$Yellow$batperc$Color_off\n"
|
||||
exit 0
|
||||
fi
|
||||
for i in $batteries; do
|
||||
batfull=$(cat /sys/class/power_supply/$i/energy_full)
|
||||
batnow=$(cat /sys/class/power_supply/$i/energy_now)
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user