Commit 39e61614 authored by Marc Cornellà's avatar Marc Cornellà
Browse files

Clean up Linux battery commands and syntax

parent 1bd7a7ad
...@@ -116,17 +116,17 @@ elif [[ "$OSTYPE" = freebsd* ]] ; then ...@@ -116,17 +116,17 @@ elif [[ "$OSTYPE" = freebsd* ]] ; then
elif [[ "$OSTYPE" = linux* ]] ; then elif [[ "$OSTYPE" = linux* ]] ; then
function battery_is_charging() { function battery_is_charging() {
! [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ! acpi 2>/dev/null | command grep -q '^Battery.*Discharging'
} }
function battery_pct() { function battery_pct() {
if (( $+commands[acpi] )) ; then if (( $+commands[acpi] )) ; then
echo "$(acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')" acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]'
fi fi
} }
function battery_pct_remaining() { function battery_pct_remaining() {
if [ ! $(battery_is_charging) ] ; then if ! battery_is_charging; then
battery_pct battery_pct
else else
echo "External Power" echo "External Power"
...@@ -134,15 +134,17 @@ elif [[ "$OSTYPE" = linux* ]] ; then ...@@ -134,15 +134,17 @@ elif [[ "$OSTYPE" = linux* ]] ; then
} }
function battery_time_remaining() { function battery_time_remaining() {
if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then if ! battery_is_charging; then
echo $(acpi 2>/dev/null | cut -f3 -d ',') acpi 2>/dev/null | cut -f3 -d ','
fi fi
} }
function battery_pct_prompt() { function battery_pct_prompt() {
b=$(battery_pct_remaining) local b=$(battery_pct_remaining)
if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then if battery_is_charging; then
if [ $b -gt 50 ] ; then echo "∞"
else
if [[ $b -gt 50 ]]; then
color='green' color='green'
elif [ $b -gt 20 ] ; then elif [ $b -gt 20 ] ; then
color='yellow' color='yellow'
...@@ -150,8 +152,6 @@ elif [[ "$OSTYPE" = linux* ]] ; then ...@@ -150,8 +152,6 @@ elif [[ "$OSTYPE" = linux* ]] ; then
color='red' color='red'
fi fi
echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}" echo "%{$fg[$color]%}$(battery_pct_remaining)%%%{$reset_color%}"
else
echo "∞"
fi fi
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment