summaryrefslogtreecommitdiff
path: root/plugins/battery
diff options
context:
space:
mode:
authorPavol Juhas <pavol.juhas@gmail.com>2014-03-17 19:48:10 -0400
committerPavol Juhas <pavol.juhas@gmail.com>2014-03-17 19:48:10 -0400
commit6952105bfe1fd4121fd355dc5f8ec5e03de5541c (patch)
tree604e65e52df88e28f99f49b939aa9547eb009b1c /plugins/battery
parented19ffee5ecc0db6617c1ae753e515d60cb486c6 (diff)
parentca900216302aa1138c793971cf877b5d4e88fb06 (diff)
downloadzsh-6952105bfe1fd4121fd355dc5f8ec5e03de5541c.tar.gz
zsh-6952105bfe1fd4121fd355dc5f8ec5e03de5541c.tar.bz2
zsh-6952105bfe1fd4121fd355dc5f8ec5e03de5541c.zip
Merge branch 'master' of https://github.com/robbyrussell/oh-my-zsh
Diffstat (limited to 'plugins/battery')
-rw-r--r--plugins/battery/battery.plugin.zsh39
1 files changed, 24 insertions, 15 deletions
diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
index 16ad3e651..b16a75c5b 100644
--- a/plugins/battery/battery.plugin.zsh
+++ b/plugins/battery/battery.plugin.zsh
@@ -17,12 +17,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
}
@@ -30,7 +34,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
@@ -58,9 +66,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 +104,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() {