Update battery.plugin.bash
- Add WIndows Bash checker. - Clean and organize the code.pull/968/head
parent
7a51ea23ee
commit
176cf00f6c
|
|
@ -10,6 +10,10 @@ ac_adapter_connected(){
|
||||||
then
|
then
|
||||||
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
|
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
|
||||||
return $?
|
return $?
|
||||||
|
elif command_exists WMIC;
|
||||||
|
then
|
||||||
|
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2'
|
||||||
|
return $?
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,13 +26,17 @@ ac_adapter_disconnected(){
|
||||||
then
|
then
|
||||||
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No'
|
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No'
|
||||||
return $?
|
return $?
|
||||||
|
elif command_exists WMIC;
|
||||||
|
then
|
||||||
|
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1'
|
||||||
|
return $?
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
battery_percentage(){
|
battery_percentage(){
|
||||||
about 'displays battery charge as a percentage of full (100%)'
|
about 'displays battery charge as a percentage of full (100%)'
|
||||||
group 'battery'
|
group 'battery'
|
||||||
|
|
||||||
if command_exists acpi;
|
if command_exists acpi;
|
||||||
then
|
then
|
||||||
local ACPI_OUTPUT=$(acpi -b)
|
local ACPI_OUTPUT=$(acpi -b)
|
||||||
|
|
@ -38,37 +46,45 @@ battery_percentage(){
|
||||||
case $PERC_OUTPUT in
|
case $PERC_OUTPUT in
|
||||||
*%)
|
*%)
|
||||||
echo "0${PERC_OUTPUT}" | head -c 2
|
echo "0${PERC_OUTPUT}" | head -c 2
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo ${PERC_OUTPUT}
|
echo ${PERC_OUTPUT}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*" Charging"* | *" Discharging"*)
|
*" Charging"* | *" Discharging"*)
|
||||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
||||||
echo ${PERC_OUTPUT}
|
echo ${PERC_OUTPUT}
|
||||||
;;
|
;;
|
||||||
*" Full"*)
|
*" Full"*)
|
||||||
echo '100'
|
echo '100'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo '-1'
|
echo '-1'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
elif command_exists ioreg;
|
elif command_exists ioreg;
|
||||||
then
|
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: "?")}')
|
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
|
case $IOREG_OUTPUT in
|
||||||
100*)
|
100*)
|
||||||
echo '100'
|
echo '100'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo $IOREG_OUTPUT | head -c 2
|
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
|
esac
|
||||||
else
|
else
|
||||||
echo "no"
|
echo "no"
|
||||||
|
|
@ -78,7 +94,7 @@ battery_percentage(){
|
||||||
battery_charge(){
|
battery_charge(){
|
||||||
about 'graphical display of your battery charge'
|
about 'graphical display of your battery charge'
|
||||||
group 'battery'
|
group 'battery'
|
||||||
|
|
||||||
# Full char
|
# Full char
|
||||||
local F_C='▸'
|
local F_C='▸'
|
||||||
# Depleted char
|
# Depleted char
|
||||||
|
|
@ -89,55 +105,55 @@ battery_charge(){
|
||||||
local DANGER_COLOR="${red}"
|
local DANGER_COLOR="${red}"
|
||||||
local BATTERY_OUTPUT="${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${D_C}"
|
local BATTERY_OUTPUT="${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${D_C}"
|
||||||
local BATTERY_PERC=$(battery_percentage)
|
local BATTERY_PERC=$(battery_percentage)
|
||||||
|
|
||||||
case $BATTERY_PERC in
|
case $BATTERY_PERC in
|
||||||
no)
|
no)
|
||||||
echo ""
|
echo ""
|
||||||
;;
|
;;
|
||||||
9*)
|
9*)
|
||||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${F_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${F_C}${normal}"
|
||||||
;;
|
;;
|
||||||
8*)
|
8*)
|
||||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${normal}"
|
||||||
;;
|
;;
|
||||||
7*)
|
7*)
|
||||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
6*)
|
6*)
|
||||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
5*)
|
5*)
|
||||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
4*)
|
4*)
|
||||||
echo "${FULL_COLOR}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
3*)
|
3*)
|
||||||
echo "${FULL_COLOR}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
2*)
|
2*)
|
||||||
echo "${FULL_COLOR}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
1*)
|
1*)
|
||||||
echo "${FULL_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
echo "${FULL_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
05)
|
05)
|
||||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
04)
|
04)
|
||||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
03)
|
03)
|
||||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
02)
|
02)
|
||||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
0*)
|
0*)
|
||||||
echo "${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
echo "${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "${DANGER_COLOR}UNPLG${normal}"
|
echo "${DANGER_COLOR}UNPLG${normal}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue