conky: Update and more files
[shutils.git] / dotfiles / conky / batteryinfo.sh
diff --git a/dotfiles/conky/batteryinfo.sh b/dotfiles/conky/batteryinfo.sh
new file mode 100755 (executable)
index 0000000..6dcc3a6
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/dash
+#
+# Stefan Huber <shuber2@gmail.com>
+# Display battery info for conky
+
+
+
+if [ -e /sys/devices/platform/smapi/ ]
+then
+       for b in `find /sys/devices/platform/smapi/ -type d -name BAT?`
+       do
+               if [ `cat $b/installed` = "1"  ]
+               then
+                       name=${b##*/}
+                       remcap=`cat $b/remaining_capacity`
+                       remcapper=`cat $b/remaining_percent`
+                       ratenow=`cat $b/power_now`
+                       rateavg=`cat $b/power_avg`
+                       remtime=`cat $b/remaining_running_time`
+                       tempmilli=`cat $b/temperature`
+                       temp=`echo "$tempmilli/1000" | bc`
+
+                       if [ "$remtime" = "not_discharging" ]; then
+                               remtime=`cat $b/remaining_charging_time`
+                       fi
+                       if [ "$remtime" = "not_charging" ]; then
+                               remtime="--"
+                       fi
+
+                       echo "$name rate:  $ratenow mW [~ $rateavg mW]" 
+                       echo "rem:   $remcap mWh [$remcapper%, $remtime min]" 
+                       #echo "$name temp:  $tempĀ°C"
+               fi
+       done
+else
+       for b in `find /proc/acpi/battery/ -type d -name BAT?`
+       do
+               if [ `grep -c -E "^present: *yes" $b/state` = "1" ]
+               then
+                       name=${b##*/}
+                       fullcap=`grep "last full capacity" $b/info | awk ' { print $4 } '`
+                       remcap=`grep "remaining capacity" $b/state | awk ' { print $3 } '`
+                       rate=`grep "present rate" $b/state | awk ' { print $3 } '`
+
+                       if [ $rate = "0" ]; then
+                               remtime="--"
+                       else
+                               remtime=`echo "$remcap*60/$rate" | bc`
+                       fi
+
+                       remcapper=`echo "$remcap*100/$fullcap" | bc `
+
+                       echo "$name rate:  $rate mW" 
+                       echo "$name rem.:  $remcap mWh [$remcapper%, $remtime min]" 
+               fi
+       done
+fi
+
+