plugin/battery: fix handling of multiple batteries with `upower`
parent
fdff1d81cd
commit
029e53a433
|
|
@ -4,8 +4,8 @@ about-plugin 'display info about your battery charge level'
|
||||||
function ac_adapter_connected() {
|
function ac_adapter_connected() {
|
||||||
local batteries
|
local batteries
|
||||||
if _command_exists upower; then
|
if _command_exists upower; then
|
||||||
batteries="$(upower -e | grep --max-count=1 -i BAT)"
|
IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
|
||||||
upower -i "${batteries}" | grep 'state' | grep -q 'charging\|fully-charged'
|
upower -i "${batteries[0]:-}" | grep 'state' | grep -q 'charging\|fully-charged'
|
||||||
elif _command_exists acpi; then
|
elif _command_exists acpi; then
|
||||||
acpi -a | grep -q "on-line"
|
acpi -a | grep -q "on-line"
|
||||||
elif _command_exists pmset; then
|
elif _command_exists pmset; then
|
||||||
|
|
@ -20,8 +20,8 @@ function ac_adapter_connected() {
|
||||||
function ac_adapter_disconnected() {
|
function ac_adapter_disconnected() {
|
||||||
local batteries
|
local batteries
|
||||||
if _command_exists upower; then
|
if _command_exists upower; then
|
||||||
batteries="$(upower -e | grep --max-count=1 -i BAT)"
|
IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
|
||||||
upower -i "${batteries}" | grep 'state' | grep -q 'discharging'
|
upower -i "${batteries[0]:-}" | grep 'state' | grep -q 'discharging'
|
||||||
elif _command_exists acpi; then
|
elif _command_exists acpi; then
|
||||||
acpi -a | grep -q "off-line"
|
acpi -a | grep -q "off-line"
|
||||||
elif _command_exists pmset; then
|
elif _command_exists pmset; then
|
||||||
|
|
@ -40,8 +40,8 @@ function battery_percentage() {
|
||||||
local command_output batteries
|
local command_output batteries
|
||||||
|
|
||||||
if _command_exists upower; then
|
if _command_exists upower; then
|
||||||
batteries="$(upower --enumerate | grep --max-count=1 -i BAT)"
|
IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
|
||||||
command_output="$(upower --show-info "${batteries:-}" | grep percentage | grep -o '[0-9]\+' | head -1)"
|
command_output="$(upower --show-info "${batteries[0]:-}" | grep percentage | grep -o '[0-9]\+' | head -1)"
|
||||||
elif _command_exists acpi; then
|
elif _command_exists acpi; then
|
||||||
command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}')
|
command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}')
|
||||||
elif _command_exists pmset; then
|
elif _command_exists pmset; then
|
||||||
|
|
|
||||||
|
|
@ -199,8 +199,7 @@ function setup_upower {
|
||||||
function upower {
|
function upower {
|
||||||
case $1 in
|
case $1 in
|
||||||
'-e'|'--enumerate')
|
'-e'|'--enumerate')
|
||||||
# don't just `echo` twice because `grep` will close the pipe after matching the first line...
|
printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery"
|
||||||
echo "$BAT0"$'\n'"/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery"
|
|
||||||
;;
|
;;
|
||||||
'-i'|'--show-info')
|
'-i'|'--show-info')
|
||||||
if [[ $2 == "$BAT0" ]]
|
if [[ $2 == "$BAT0" ]]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue