Support upower for battery plugin

pull/976/head
shine 2017-06-11 14:33:22 +05:30
parent 07b9305d2f
commit 98f13c7b6a
1 changed files with 22 additions and 3 deletions

View File

@ -2,7 +2,11 @@ cite about-plugin
about-plugin 'display info about your battery charge level' about-plugin 'display info about your battery charge level'
ac_adapter_connected(){ ac_adapter_connected(){
if command_exists acpi; if command_exists upower;
then
upower --show-info $(upower --enumerate | grep BAT) | grep --quiet state | grep --quiet charging
return $?
elif command_exists acpi;
then then
acpi -a | grep -q "on-line" acpi -a | grep -q "on-line"
return $? return $?
@ -18,7 +22,11 @@ ac_adapter_connected(){
} }
ac_adapter_disconnected(){ ac_adapter_disconnected(){
if command_exists acpi; if command_exists upower;
then
upower --show-info $(upower --enumerate | grep BAT) | grep --quiet state | grep --quiet discharging
return $?
elif command_exists acpi;
then then
acpi -a | grep -q "off-line" acpi -a | grep -q "off-line"
return $? return $?
@ -37,7 +45,18 @@ 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 upower;
then
local UPOWER_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage)
case UPOWER_OUTPUT in
100*)
echo '100'
;;
*)
echo $UPOWER_OUTPUT | tail --bytes 4 | head --bytes 2
;;
esac
elif command_exists acpi;
then then
local ACPI_OUTPUT=$(acpi -b) local ACPI_OUTPUT=$(acpi -b)
case $ACPI_OUTPUT in case $ACPI_OUTPUT in