zshrc: Added a missing test on OSX battery function
authorMoviuro <moviuro+grml@gmail.com>
Tue, 23 Sep 2014 05:59:22 +0000 (07:59 +0200)
committerFrank Terbeck <ft@grml.org>
Tue, 23 Sep 2014 12:24:15 +0000 (14:24 +0200)
etc/zsh/zshrc

index bb0c784..a164fb8 100644 (file)
@@ -1755,22 +1755,24 @@ batterydarwin(){
 GRML_BATTERY_LEVEL=''
 local -a table
 table=( ${$(pmset -g ps)[(w)7,8]%%(\%|);} )
-case $table[2] in
-    charging)
-        GRML_BATTERY_LEVEL+=" ^"
-        ;;
-    discharging)
-        if (( $table[1] < 20 )) ; then
-            GRML_BATTERY_LEVEL+=" !v"
-        else
-            GRML_BATTERY_LEVEL+=" v"
-        fi
-        ;;
-    *)
-        GRML_BATTERY_LEVEL+=" ="
-        ;;
-esac
-GRML_BATTERY_LEVEL+="$table[1]%%"
+if [[ -n $table[2] ]] ; then
+    case $table[2] in
+        charging)
+            GRML_BATTERY_LEVEL+=" ^"
+            ;;
+        discharging)
+            if (( $table[1] < 20 )) ; then
+                GRML_BATTERY_LEVEL+=" !v"
+            else
+                GRML_BATTERY_LEVEL+=" v"
+            fi
+            ;;
+        *)
+            GRML_BATTERY_LEVEL+=" ="
+            ;;
+    esac
+    GRML_BATTERY_LEVEL+="$table[1]%%"
+fi
 }
 
 # set variable debian_chroot if running in a chroot with /etc/debian_chroot