From 485439dddb76c48993dfb23534fc2327b968ec15 Mon Sep 17 00:00:00 2001
From: Peter Hoeg
Date: Thu, 29 Sep 2011 22:38:10 +0800
Subject: [PATCH] change: make battery indicator change color based on status
---
plugins/battery/battery.plugin.zsh | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
index c1cab9ec3..6eafc6093 100644
--- a/plugins/battery/battery.plugin.zsh
+++ b/plugins/battery/battery.plugin.zsh
@@ -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