diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2014-05-03 18:48:46 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2014-05-03 18:48:46 -0300 |
commit | 5dc23d23b5c09c87d74538dd52eb5d2dbe78e8e3 (patch) | |
tree | bc405d949492350d3c62aabc75a70f0c80595569 | |
parent | faf776433b474217325c56968187bf35a4e1b911 (diff) | |
download | scripts-5dc23d23b5c09c87d74538dd52eb5d2dbe78e8e3.tar.gz scripts-5dc23d23b5c09c87d74538dd52eb5d2dbe78e8e3.tar.bz2 |
Adding battery script for awesome
-rwxr-xr-x | battery | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -0,0 +1,60 @@ +#!/bin/bash +# +# See http://blog.lick-me.org/2013/08/yet-another-battery-widget-awesome-3-5-1/ +# + +# Returns battery charge as a percentage. +# Thanks http://blmath.wordpress.com/2010/03/19/bash-function-to-get-battery-charge/ +function battery_charge { + now=`cat /sys/class/power_supply/BAT0/energy_now` + full=`cat /sys/class/power_supply/BAT0/energy_full` + out=`echo $now/$full*100 | bc -l | cut -c 1-5` + + echo $out | sed -e 's/\./,/g' + #echo "Charge: "$out"%" +} + +# Returns battery capacity as a percentage. +# Thanks http://blmath.wordpress.com/2010/03/19/bash-function-to-get-battery-charge/ +function battery_capacity { + design=`cat /sys/class/power_supply/BAT0/energy_full_design` + current=`cat /sys/class/power_supply/BAT0/energy_full` + out=`echo $current/$design*100 | bc -l | cut -c 1-5` + + echo $out | sed -e 's/\./,/g' + #echo "Capacity: "$out"%" +} + +# Basic parameters +healthy='#859900' +low='#b58900' +discharge='#dc322f' + +# Get battery status +if [ -e "/sys/class/power_supply/BAT0/charge" ]; then + charge=`cat /sys/class/power_supply/BAT0/charge` +else + charge="`battery_charge`" +fi + +# Set battery level indication +if (($charge <= 25)); then + chargeColor=$low +else + chargeColor=$healthy +fi + +# Get battery status +status=`cat /sys/class/power_supply/BAT0/status` + +# Set battery status indication +if [[ "$status" = "Discharging" ]]; then + statusColor=$discharge + status="▼" +else + statusColor=$healthy + status="▲" +fi + +# Output +echo "<span color=\"$chargeColor\">$charge%</span> <span color=\"$statusColor\">$status</span>" |