* usr/lib/byobu/battery:

- protect against division by zero
This commit is contained in:
Dustin Kirkland 2011-10-26 09:41:17 -05:00
commit 6e94f12096
2 changed files with 23 additions and 19 deletions

4
debian/changelog vendored
View file

@ -1,6 +1,8 @@
byobu (4.44) unreleased; urgency=low byobu (4.44) unreleased; urgency=low
* UNRELEASED [ Dustin Kirkland ]
* usr/lib/byobu/battery:
- protect against division by zero
-- Dustin Kirkland <kirkland@ubuntu.com> Sat, 22 Oct 2011 03:21:46 -0500 -- Dustin Kirkland <kirkland@ubuntu.com> Sat, 22 Oct 2011 03:21:46 -0500

View file

@ -67,25 +67,27 @@ __battery() {
;; ;;
esac esac
done done
percent=$(((100*$rem)/$full)) if [ $rem -ge 0 ] && [ $full -gt 0 ]; then
if [ "$percent" -lt 33 ]; then percent=$(((100*$rem)/$full))
color="R k" if [ "$percent" -lt 33 ]; then
bcolor="b R k" color="R k"
elif [ "$percent" -lt 67 ]; then bcolor="b R k"
color="Y k" elif [ "$percent" -lt 67 ]; then
bcolor="b Y k" color="Y k"
else bcolor="b Y k"
color="G k" else
bcolor="b G k" color="G k"
bcolor="b G k"
fi
percent="$percent$PCT"
case $state in
charging|Charging|Unknown) sign="+" ;;
discharging|Discharging) sign="-" ;;
charged|Unknown) sign="="; percent="" ;;
*) sign="$state" ;;
esac
color $bcolor; printf "%s" "$percent"; color -; color $color; printf "%s" "$sign"; color --
fi fi
percent="$percent$PCT"
case $state in
charging|Charging|Unknown) sign="+" ;;
discharging|Discharging) sign="-" ;;
charged|Unknown) sign="="; percent="" ;;
*) sign="$state" ;;
esac
color $bcolor; printf "%s" "$percent"; color -; color $color; printf "%s" "$sign"; color --
} }
# vi: syntax=sh ts=4 noexpandtab # vi: syntax=sh ts=4 noexpandtab