diff options
author | Ron Shapiro <shapiro.rd@gmail.com> | 2013-04-20 22:37:36 -0400 |
---|---|---|
committer | Ron Shapiro <shapiro.rd@gmail.com> | 2013-04-20 22:37:36 -0400 |
commit | bc385531b0e71b90b800502117bbdc8d1531e4c2 (patch) | |
tree | 7a4da195648fb836554efaea2c8668c598c41ca5 /plugins/battery/battery.plugin.zsh | |
parent | 85426a57a2561f675a6ad51754d6687c3ec571c2 (diff) | |
download | zsh-bc385531b0e71b90b800502117bbdc8d1531e4c2.tar.gz zsh-bc385531b0e71b90b800502117bbdc8d1531e4c2.tar.bz2 zsh-bc385531b0e71b90b800502117bbdc8d1531e4c2.zip |
Separate the battery_pct_remaining data into it's own function so that it can be obtained even if the battery is connected.
Diffstat (limited to 'plugins/battery/battery.plugin.zsh')
-rw-r--r-- | plugins/battery/battery.plugin.zsh | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 95f890632..0c7c9421f 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -10,12 +10,16 @@ if [[ $(uname) == "Darwin" ]] ; then + function battery_pct() { + typeset -F maxcapacity=$(ioreg -rc "AppleSmartBattery"| grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //') + typeset -F currentcapacity=$(ioreg -rc "AppleSmartBattery"| grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //') + integer i=$(((currentcapacity/maxcapacity) * 100)) + echo $i + } + function battery_pct_remaining() { if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then - typeset -F maxcapacity=$(ioreg -rc "AppleSmartBattery"| grep '^.*"MaxCapacity"\ =\ ' | sed -e 's/^.*"MaxCapacity"\ =\ //') - typeset -F currentcapacity=$(ioreg -rc "AppleSmartBattery"| grep '^.*"CurrentCapacity"\ =\ ' | sed -e 's/^.*CurrentCapacity"\ =\ //') - integer i=$(((currentcapacity/maxcapacity) * 100)) - echo $i + battery_pct else echo "External Power" fi |