Consolidated cases for acpi
parent
3aed38c79f
commit
486c9e1382
|
|
@ -60,30 +60,8 @@ battery_percentage(){
|
||||||
elif _command_exists acpi;
|
elif _command_exists acpi;
|
||||||
then
|
then
|
||||||
local ACPI_OUTPUT=$(acpi -b)
|
local ACPI_OUTPUT=$(acpi -b)
|
||||||
case $ACPI_OUTPUT in
|
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
||||||
*" Unknown"*)
|
echo ${PERC_OUTPUT:--1}
|
||||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 22 | tail -c 2)
|
|
||||||
case $PERC_OUTPUT in
|
|
||||||
*%)
|
|
||||||
echo "0${PERC_OUTPUT}" | head -c 2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo ${PERC_OUTPUT}
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
|
|
||||||
*" Charging"* | *" Discharging"*)
|
|
||||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
|
||||||
echo ${PERC_OUTPUT}
|
|
||||||
;;
|
|
||||||
*" Full"*)
|
|
||||||
echo '100'
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo '-1'
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
elif _command_exists pmset;
|
elif _command_exists pmset;
|
||||||
then
|
then
|
||||||
local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p')
|
local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p')
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,15 @@ function setup_acpi {
|
||||||
|
|
||||||
setup_acpi "4%" ""
|
setup_acpi "4%" ""
|
||||||
|
|
||||||
|
run battery_percentage
|
||||||
|
assert_output "4"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins battery: battery-percentage with acpi, no status' {
|
||||||
|
setup_command_exists "acpi"
|
||||||
|
|
||||||
|
setup_acpi "" ""
|
||||||
|
|
||||||
run battery_percentage
|
run battery_percentage
|
||||||
assert_output "-1"
|
assert_output "-1"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue