Fix battery plugin when acpi writes to stderr (#5413)

* Fix battery plugin when acpi writes to stderr
* Make stderr redirection in battery plugin more idiomatic
This commit is contained in:
Reed Riley 2016-09-14 20:01:10 -04:00 committed by Marc Cornellà
parent ce4d8a5cad
commit 59c66dbfc2

View File

@ -67,12 +67,12 @@ if [[ "$OSTYPE" = darwin* ]] ; then
elif [[ $(uname) == "Linux" ]] ; then elif [[ $(uname) == "Linux" ]] ; then
function battery_is_charging() { function battery_is_charging() {
! [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ! [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]]
} }
function battery_pct() { function battery_pct() {
if (( $+commands[acpi] )) ; then if (( $+commands[acpi] )) ; then
echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" echo "$(acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')"
fi fi
} }
@ -85,14 +85,14 @@ elif [[ $(uname) == "Linux" ]] ; then
} }
function battery_time_remaining() { function battery_time_remaining() {
if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
echo $(acpi | cut -f3 -d ',') echo $(acpi 2>/dev/null | cut -f3 -d ',')
fi fi
} }
function battery_pct_prompt() { function battery_pct_prompt() {
b=$(battery_pct_remaining) b=$(battery_pct_remaining)
if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
if [ $b -gt 50 ] ; then if [ $b -gt 50 ] ; then
color='green' color='green'
elif [ $b -gt 20 ] ; then elif [ $b -gt 20 ] ; then