change: make battery indicator change color based on status

This commit is contained in:
Peter Hoeg 2011-09-29 22:38:10 +08:00
commit 485439dddb

View file

@ -1,9 +1,20 @@
if [[ $(acpi | grep -c ^Battery) -gt 0 ]] ; then
if [[ $(acpi | grep -c '^Battery.*Discharging') -gt 0 ]] ; then
function battery_pct_remaining() { echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" }
function battery_time_remaining() { echo $(acpi | cut -f3 -d ',') }
function battery_pct_prompt() { echo "%{$fg[red]%}[$(battery_pct_remaining)]%{$reset_color%}" }
function battery_pct_prompt() {
b=$(battery_pct_remaining)
if [ $b -gt 50 ] ; then
color='green'
elif [ $b -gt 20 ] ; then
color='yellow'
else
color='red'
fi
echo "%{$fg[$color]%}[$(battery_pct_remaining)%%]%{$reset_color%}"
}
else
error_msg='no battery'
function battery_pct_remaining() { echo $error_msg }
function battery_time_remaining() { echo $error_msg }
function battery_pct_prompt() { echo '' }
fi