Update battery.plugin.bash

- Add WIndows Bash checker.
- Clean and organize the code.
pull/968/head
Luis Felipe Sánchez 2017-05-25 23:27:12 -05:00 committed by GitHub
parent 7a51ea23ee
commit 176cf00f6c
1 changed files with 47 additions and 31 deletions

View File

@ -10,6 +10,10 @@ ac_adapter_connected(){
then
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
return $?
elif command_exists WMIC;
then
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2'
return $?
fi
}
@ -22,6 +26,10 @@ ac_adapter_disconnected(){
then
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No'
return $?
elif command_exists WMIC;
then
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1'
return $?
fi
}
@ -58,9 +66,6 @@ battery_percentage(){
esac
elif command_exists ioreg;
then
# http://hints.macworld.com/article.php?story=20100130123935998
#local IOREG_OUTPUT_10_6=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}')
#local IOREG_OUTPUT_10_5=$(ioreg -l | grep -i capacity | grep -v Legacy| tr '\n' ' | ' | awk '{printf("%.2f%%", $14/$7 * 100)}')
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
case $IOREG_OUTPUT in
100*)
@ -70,6 +75,17 @@ battery_percentage(){
echo $IOREG_OUTPUT | head -c 2
;;
esac
elif command_exists WMIC;
then
local WINPC=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*')
case $WINPC in
100*)
echo '100'
;;
*)
echo $WINPC
;;
esac
else
echo "no"
fi