Refactored command output handling
parent
a573b63da2
commit
86a87a33b5
|
|
@ -53,29 +53,28 @@ 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'
|
||||||
|
|
||||||
|
declare COMMAND_OUTPUT="no"
|
||||||
|
|
||||||
if _command_exists upower;
|
if _command_exists upower;
|
||||||
then
|
then
|
||||||
local UPOWER_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | grep -o "[0-9]\+" | head -1)
|
COMMAND_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | grep -o "[0-9]\+" | head -1)
|
||||||
echo ${UPOWER_OUTPUT:--1}
|
|
||||||
elif _command_exists acpi;
|
elif _command_exists acpi;
|
||||||
then
|
then
|
||||||
local PERC_OUTPUT=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
COMMAND_OUTPUT=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
||||||
echo ${PERC_OUTPUT:--1}
|
|
||||||
elif _command_exists pmset;
|
elif _command_exists pmset;
|
||||||
then
|
then
|
||||||
local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o "[0-9]\+" | head -1)
|
COMMAND_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o "[0-9]\+" | head -1)
|
||||||
echo ${PMSET_OUTPUT:--1}
|
|
||||||
elif _command_exists ioreg;
|
elif _command_exists ioreg;
|
||||||
then
|
then
|
||||||
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%d"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
|
COMMAND_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%d"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
|
||||||
echo ${IOREG_OUTPUT:--1}
|
|
||||||
elif _command_exists WMIC;
|
elif _command_exists WMIC;
|
||||||
then
|
then
|
||||||
local WINPC=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
|
COMMAND_OUTPUT=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
|
||||||
echo ${WINPC:--1}
|
|
||||||
else
|
else
|
||||||
echo "no"
|
COMMAND_OUTPUT="no"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo ${COMMAND_OUTPUT:--1}
|
||||||
}
|
}
|
||||||
|
|
||||||
battery_charge(){
|
battery_charge(){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue