From b87f3067b595bd0db448654e9b85e38cfd881a99 Mon Sep 17 00:00:00 2001 From: Nariyasu Heseri Date: Sat, 29 Jan 2022 03:17:50 +0900 Subject: [PATCH] plugin/battery: bug fix When `upower --enumerate | grep -i BAT` returns multiple lines of results (which are file paths), the added quotation (from commit 3cb5f3f7e66345a329cae8ad112f1ecbedc60dab) concatenates them all to provide an invalid path. Thus to make the plugin work as before the commit, take only the first line of the results. --- plugins/available/battery.plugin.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index dc18167c..8b1a4e08 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -3,7 +3,7 @@ about-plugin 'display info about your battery charge level' function ac_adapter_connected() { if _command_exists upower; then - upower -i "$(upower -e | grep -i BAT)" | grep 'state' | grep -q 'charging\|fully-charged' + upower -i "$(upower -e | grep -i BAT | head -n 1)" | grep 'state' | grep -q 'charging\|fully-charged' elif _command_exists acpi; then acpi -a | grep -q "on-line" elif _command_exists pmset; then @@ -17,7 +17,7 @@ function ac_adapter_connected() { function ac_adapter_disconnected() { if _command_exists upower; then - upower -i "$(upower -e | grep -i BAT)" | grep 'state' | grep -q 'discharging' + upower -i "$(upower -e | grep -i BAT | head -n 1)" | grep 'state' | grep -q 'discharging' elif _command_exists acpi; then acpi -a | grep -q "off-line" elif _command_exists pmset; then @@ -36,7 +36,7 @@ function battery_percentage() { local command_output="no" if _command_exists upower; then - command_output=$(upower --show-info "$(upower --enumerate | grep -i BAT)" | grep percentage | grep -o "[0-9]\+" | head -1) + command_output=$(upower --show-info "$(upower --enumerate | grep -i BAT | head -n 1)" | grep percentage | grep -o "[0-9]\+" | head -1) elif _command_exists acpi; then command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}') elif _command_exists pmset; then