zshrc: fixed the FreeBSD battery function
authorMoviuro <moviuro+grml@gmail.com>
Fri, 3 Oct 2014 15:24:20 +0000 (17:24 +0200)
committerFrank Terbeck <ft@grml.org>
Fri, 3 Oct 2014 15:47:38 +0000 (17:47 +0200)
Even if there are no batteries and/or /dev/acpi is unavailable, the function won't print =% =%

etc/zsh/zshrc

index a19c9ac..d3d73b1 100644 (file)
@@ -1729,8 +1729,8 @@ GRML_BATTERY_LEVEL=''
 local num
 local -A table
 for num in 0 1 ; do
-    table=( ${=${${${${${(M)${(f)"$(acpiconf -i $num)"}:#(State|Remaining capacity):*}%%( ##|%)}//:[ $'\t']##/@}// /-}//@/ }} )
-    if [[ $table[State] != "not-present" ]] ; then
+    table=( ${=${${${${${(M)${(f)"$(acpiconf -i $num 2>&1)"}:#(State|Remaining capacity):*}%%( ##|%)}//:[ $'\t']##/@}// /-}//@/ }} )
+    if [[ -n $table ]] && [[ $table[State] != "not-present" ]] ; then
         case $table[State] in
             *discharging*)
                 if (( $table[Remaining-capacity] < 20 )) ; then