From ae1973de443525daeb87df9973ae83c6c9210cfe Mon Sep 17 00:00:00 2001 From: Ron Shapiro Date: Mon, 29 Apr 2013 10:18:32 -0400 Subject: plugged_in function --- plugins/battery/battery.plugin.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'plugins/battery') diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 0c7c9421f..785386a12 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -16,12 +16,16 @@ if [[ $(uname) == "Darwin" ]] ; then integer i=$(((currentcapacity/maxcapacity) * 100)) echo $i } + + function plugged_in() { + [ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ] + } function battery_pct_remaining() { - if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then - battery_pct - else + if plugged_in ; then echo "External Power" + else + battery_pct fi } -- cgit v1.2.3-70-g09d2 From fdd864bd5b5444848c492454e025257f3c4fa675 Mon Sep 17 00:00:00 2001 From: Chris Wiggins Date: Mon, 17 Feb 2014 13:32:24 +1300 Subject: Update battery plugin to show calculating - OSX Instantly after removing the charger, I have found that the "AvgTimeToEmpty" value can swing to rediculous values. Apple's current claim is that the max battery life is 12 hours, so any value larger than this is considered a "time is being calculated" value. --- plugins/battery/battery.plugin.zsh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'plugins/battery') diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 16ad3e651..2c00ff141 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -30,7 +30,11 @@ if [[ $(uname) == "Darwin" ]] ; then local smart_battery_status="$(ioreg -rc "AppleSmartBattery")" if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //') - echo "~$((timeremaining / 60)):$((timeremaining % 60))" + if [ $timeremaining -gt 720 ] ; then + echo "::" + else + echo "~$((timeremaining / 60)):$((timeremaining % 60))" + fi else echo "∞" fi -- cgit v1.2.3-70-g09d2 From 564a708d6af90b1bc5bf4d13e7ad80abca92ad74 Mon Sep 17 00:00:00 2001 From: Thiago Perrotta Date: Sun, 2 Mar 2014 14:47:35 -0300 Subject: added the linux implementation to the battery plugin --- plugins/battery/battery.plugin.zsh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'plugins/battery') diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 16ad3e651..670c6a47d 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -58,9 +58,19 @@ if [[ $(uname) == "Darwin" ]] ; then elif [[ $(uname) == "Linux" ]] ; then + function battery_is_charging() { + ! [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] + } + + function battery_pct() { + echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" + } + function battery_pct_remaining() { - if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then - echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" + if [ ! $(battery_is_charging) ] ; then + battery_pct + else + echo "External Power" fi } @@ -86,15 +96,6 @@ elif [[ $(uname) == "Linux" ]] ; then fi } - function battery_pct() { - # todo for on linux - } - - function battery_is_charging() { - # todo on linux - false - } - else # Empty functions so we don't cause errors in prompts function battery_pct_remaining() { -- cgit v1.2.3-70-g09d2