浏览代码

Merge pull request #1738 from ronshapiro/master

Battery plugin changes
Robby Russell 12 年之前
父节点
当前提交
56b4d4d639
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      plugins/battery/battery.plugin.zsh

+ 8 - 4
plugins/battery/battery.plugin.zsh

@@ -10,12 +10,16 @@
 
 
 if [[ $(uname) == "Darwin" ]] ; then
 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() {
   function battery_pct_remaining() {
     if [[ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
     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
     else
       echo "External Power"
       echo "External Power"
     fi
     fi