From c02444d81e98559e5a7b485beeee0e0222789bfb Mon Sep 17 00:00:00 2001 From: Nikhil Gupta Date: Sun, 12 Oct 2014 18:44:08 +0530 Subject: [PATCH] suppressed error on linux from battery plugin, added fully-charged implementation on OSX --- plugins/battery/battery.plugin.zsh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 014bb15dd..a1297e066 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -22,6 +22,10 @@ if [[ "$OSTYPE" = darwin* ]] ; then [ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ] } + function fully_charged() { + [[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"FullyCharged"\ =\ ' | sed -e 's/^.*"FullyCharged"\ =\ //') == "Yes" ]] + } + function battery_pct_remaining() { if plugged_in ; then echo "External Power" @@ -70,9 +74,16 @@ elif [[ $(uname) == "Linux" ]] ; then ! [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] } + function plugged_in() { + battery_is_charging + } + + function fully_charged() { + } + function battery_pct() { if (( $+commands[acpi] )) ; then - echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" + echo "$(acpi 2&>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')" fi } @@ -91,7 +102,7 @@ elif [[ $(uname) == "Linux" ]] ; then } function battery_pct_prompt() { - b=$(battery_pct_remaining) + b=$(battery_pct_remaining) if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then if [ $b -gt 50 ] ; then color='green' @@ -107,7 +118,17 @@ elif [[ $(uname) == "Linux" ]] ; then } else + # Empty functions so we don't cause errors in prompts + function plugged_in() { + } + + function fully_charged() { + } + + function battery_is_charging() { + } + function battery_pct_remaining() { }