Update battery.plugin.bash

Added **pmset** command that improves the process of detecting the battery and its percentage
pull/997/head
Luis Felipe Sánchez 2017-07-12 18:59:47 -05:00 committed by GitHub
parent d2fb415856
commit a3e714e175
1 changed files with 19 additions and 0 deletions

View File

@ -10,6 +10,10 @@ ac_adapter_connected(){
then
acpi -a | grep -q "on-line"
return $?
elif command_exists pmset;
then
pmset -g batt | grep -q 'AC Power'
return $?
elif command_exists ioreg;
then
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
@ -30,6 +34,10 @@ ac_adapter_disconnected(){
then
acpi -a | grep -q "off-line"
return $?
elif command_exists pmset;
then
pmset -g batt | grep -q 'Battery Power'
return $?
elif command_exists ioreg;
then
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No'
@ -76,6 +84,17 @@ battery_percentage(){
echo '-1'
;;
esac
elif command_exists pmset;
then
local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p')
case $PMSET_OUTPUT in
100*)
echo '100'
;;
*)
echo $PMSET_OUTPUT | head -c 2
;;
esac
elif command_exists ioreg;
then
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: "?")}')