From 6428159e581bb4b006fba290e44ab8fc22e1c4bc Mon Sep 17 00:00:00 2001 From: Michele Campeotto Date: Wed, 1 Aug 2012 16:53:54 -0700 Subject: [PATCH] added battery plugin support for OS X --- plugins/battery/battery.plugin.zsh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index bc75c5cf9..f12130fc8 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -1,8 +1,18 @@ if [[ $(acpi 2&>/dev/null | 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() { - b=$(battery_pct_remaining) +elif [[ $(pmset -g ps 2&>/dev/null | grep -c -- '-InternalBattery-') -gt 0 ]] ; then + function battery_pct_remaining() { echo "$(pmset -g ps | tr -cd '[:digit:][:blank:]:' | awk '{print $2}')" } + function battery_time_remaining() { echo "$(pmset -g ps | tr -cd '[:digit:][:blank:]:' | awk '{print $3}')" } +else + error_msg='no battery' + function battery_pct_remaining() { echo $error_msg } + function battery_time_remaining() { echo $error_msg } +fi + +function battery_pct_prompt() { + b=$(battery_pct_remaining) + if [[ $b == <-> ]] ; then if [ $b -gt 50 ] ; then color='green' elif [ $b -gt 20 ] ; then @@ -10,11 +20,8 @@ if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then 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 + echo "%{$fg[$color]%}[$b%%]%{$reset_color%}" + else + echo '' + fi +}