fb2d6eb5679370b7e8c971ab75b85d8f57d0da1b

Author
Reed Riley <john.reed.riley@gmail.com>
Committer
Reed Riley <john.reed.riley@gmail.com>
Date

Message

Fixed errors if acpitool isn't installed on linux

Diff

 1diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh
 2index b16a75c5b1cb07466b83673c32e29183dbe7a684..32dd4b624dfd96081f3a2d518af1d4b763089bc7 100644
 3--- a/plugins/battery/battery.plugin.zsh
 4+++ b/plugins/battery/battery.plugin.zsh
 5@@ -21,7 +21,7 @@ if [[ $(uname) == "Darwin" ]] ; then
 6   function plugged_in() {
 7     [ $(ioreg -rc AppleSmartBattery | grep -c '^.*"ExternalConnected"\ =\ Yes') -eq 1 ]
 8   }
 9-  
10+
11   function battery_pct_remaining() {
12     if plugged_in ; then
13       echo "External Power"
14@@ -31,7 +31,7 @@ if [[ $(uname) == "Darwin" ]] ; then
15   }
16 
17   function battery_time_remaining() {
18-  	local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
19+    local smart_battery_status="$(ioreg -rc "AppleSmartBattery")"
20     if [[ $(echo $smart_battery_status | grep -c '^.*"ExternalConnected"\ =\ No') -eq 1 ]] ; then
21       timeremaining=$(echo $smart_battery_status | grep '^.*"AvgTimeToEmpty"\ =\ ' | sed -e 's/^.*"AvgTimeToEmpty"\ =\ //')
22       if [ $timeremaining -gt 720 ] ; then
23@@ -59,9 +59,9 @@ if [[ $(uname) == "Darwin" ]] ; then
24       echo "∞"
25     fi
26   }
27-  
28+
29   function battery_is_charging() {
30-	  [[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"IsCharging"\ =\ ' | sed -e 's/^.*"IsCharging"\ =\ //') == "Yes" ]]
31+    [[ $(ioreg -rc "AppleSmartBattery"| grep '^.*"IsCharging"\ =\ ' | sed -e 's/^.*"IsCharging"\ =\ //') == "Yes" ]]
32   }
33 
34 elif [[ $(uname) == "Linux"  ]] ; then
35@@ -71,7 +71,9 @@ elif [[ $(uname) == "Linux"  ]] ; then
36   }
37 
38   function battery_pct() {
39-    echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" 
40+    if (( $+commands[acpi] )) ; then
41+      echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')"
42+    fi
43   }
44 
45   function battery_pct_remaining() {
46@@ -103,7 +105,7 @@ elif [[ $(uname) == "Linux"  ]] ; then
47       echo "∞"
48     fi
49   }
50-  
51+
52 else
53   # Empty functions so we don't cause errors in prompts
54   function battery_pct_remaining() {
55@@ -136,7 +138,7 @@ function battery_level_gauge() {
56   if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then
57     local filled=$(((( $battery_remaining_percentage + $gauge_slots - 1) / $gauge_slots)));
58     local empty=$(($gauge_slots - $filled));
59-	
60+
61     if [[ $filled -gt $green_threshold ]]; then local gauge_color=$color_green;
62     elif [[ $filled -gt $yellow_threshold ]]; then local gauge_color=$color_yellow;
63     else local gauge_color=$color_red;
64@@ -144,10 +146,9 @@ function battery_level_gauge() {
65   else
66     local filled=$gauge_slots;
67     local empty=0;
68-  	filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'};
69+    filled_symbol=${BATTERY_UNKNOWN_SYMBOL:-'.'};
70   fi
71 
72-  
73   local charging=' ' && battery_is_charging && charging=$charging_symbol;
74 
75   printf ${charging_color//\%/\%\%}$charging${color_reset//\%/\%\%}${battery_prefix//\%/\%\%}${gauge_color//\%/\%\%}