From 9b7923fd3ade47d639340e15b7904fcd60ac1321 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Tue, 7 Apr 2009 10:06:52 -0700 Subject: [PATCH] dynamically shade the battery percentage --- bin/battery | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/bin/battery b/bin/battery index 49f2982b..9aa812ed 100755 --- a/bin/battery +++ b/bin/battery @@ -17,7 +17,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# + search () { local str expr @@ -57,13 +57,27 @@ for bat in $BATS; do elif [ "$rem" -lt "$warn" ]; then cap_color="{= yk}" else - cap_color="{= Gk}" + cap_color="{= gk}" fi percent=$( echo "$rem" "$full" | awk '{printf "%.0f", 100*$1/$2}') - state=$(search "$statefile" "charging state: *\(.*\)") + if [ "$percent" -lt 17 ]; then + per_color="{= rk}" + elif [ "$percent" -lt 33 ]; then + per_color="{= Rk}" + elif [ "$percent" -lt 50 ]; then + per_color="{= yk}" + elif [ "$percent" -lt 67 ]; then + per_color="{= Yk}" + elif [ "$percent" -lt 83 ]; then + per_color="{= Gk}" + else + per_color="{= gk}" + fi + + state=$(search "$statefile" "charging state: *\(.*\)") case $state in charging) sign="+" @@ -79,5 +93,5 @@ for bat in $BATS; do ;; esac - printf "\005%s%d%%|%s|\005{-} " "$cap_color" "$percent" "$sign" + printf "\005%s%d%%\005{-}\005%s|%s|\005{-} " "$per_color" "$percent" "$cap_color" "$sign" done