Skip to content

Commit

Permalink
_lp_battery: refactor; less code
Browse files Browse the repository at this point in the history
  • Loading branch information
dolmen committed Dec 15, 2015
1 parent 6961f99 commit 4636e0e
Showing 1 changed file with 13 additions and 40 deletions.
53 changes: 13 additions & 40 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -1180,30 +1180,18 @@ case "$LP_OS" in
bat="${bat%%%*}" # remove everything starting at '%'

if [[ -z "${bat}" ]]; then
# not battery level found
# no battery level found
return 4

fi
echo -n "$bat"
# discharging
elif [[ "$acpi" == *"Discharging"* ]]; then
if [[ ${bat} -le $LP_BATTERY_THRESHOLD ]]; then
# under threshold
echo -n "${bat}"
return 0
else
# above threshold
echo -n "${bat}"
return 1
fi

if [[ "$acpi" == *"Discharging"* ]]; then
# under => 0, above => 1
return $(( bat > LP_BATTERY_THRESHOLD ))
# charging
elif [[ ${bat} -le $LP_BATTERY_THRESHOLD ]]; then
# under threshold
echo -n "${bat}"
return 2
else
# above threshold
echo -n "${bat}"
return 3
# under => 2, above => 3
return $(( 1 + ( bat > LP_BATTERY_THRESHOLD ) ))
fi
}
;;
Expand All @@ -1218,27 +1206,12 @@ case "$LP_OS" in
return 4
;;
discharging)
if [[ ${percent} -le $LP_BATTERY_THRESHOLD ]]; then
# under threshold
echo -n "${percent}"
return 0
else
# above threshold
echo -n "${percent}"
return 1
fi
# under => 0, above => 1
return $(( percent > LP_BATTERY_THRESHOLD ))
;;
*)
# "charging", "AC attached"
if [[ ${percent} -le $LP_BATTERY_THRESHOLD ]]; then
# under threshold
echo -n "${percent}"
return 2
else
# above threshold
echo -n "${percent}"
return 3
fi
*) # "charging", "AC attached"
# under => 2, above => 3
return $(( 1 + ( percent > LP_BATTERY_THRESHOLD ) ))
;;
esac
}
Expand Down

0 comments on commit 4636e0e

Please sign in to comment.