Browse Source

plugged_in function

Ron Shapiro 12 years ago
parent
commit
ae1973de44
1 changed files with 7 additions and 3 deletions
  1. 7 3
      plugins/battery/battery.plugin.zsh

+ 7 - 3
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
   }