diff options
author | Urbain Vaes <urbain@vaes.uk> | 2018-02-21 12:18:32 +0000 |
---|---|---|
committer | Urbain Vaes <urbain@vaes.uk> | 2018-02-21 16:46:29 +0000 |
commit | b9ea238dd7e8a56b1d171cdc76e405bb2a8584dd (patch) | |
tree | d693deb61965b724cd8630e0a061e5e762341c9c /i3/.config/i3blocks/bin/battery | |
parent | 68d822599f074c24505eea2329bfc80e2745feab (diff) |
Improve i3 status
Diffstat (limited to 'i3/.config/i3blocks/bin/battery')
-rwxr-xr-x | i3/.config/i3blocks/bin/battery | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/i3/.config/i3blocks/bin/battery b/i3/.config/i3blocks/bin/battery new file mode 100755 index 0000000..b345f16 --- /dev/null +++ b/i3/.config/i3blocks/bin/battery @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +if [ ! -d /sys/class/power_supply/BAT0 ]; then + echo "<span color='gray'></span> No battery" + exit +fi + +output="$(acpi -b)" +remaining_time=$(echo "$output" | grep -o "[0-9][0-9]:[0-9][0-9]") +<<<<<<< HEAD + +if [ -d /sys/class/power_supply/BAT0 ]; then + now_charge=$(cat /sys/class/power_supply/BAT0/now_charge) + full_charge=$(cat /sys/class/power_supply/BAT0/full_charge) + charge=$(( (100*now_charge) / full_charge )) +else + echo "" + exit +fi +======= +now_charge=$(cat /sys/class/power_supply/BAT0/now_charge) +full_charge=$(cat /sys/class/power_supply/BAT0/full_charge) +charge=$(( (100*now_charge) / full_charge )) +# charge=$(echo "$output" | grep -oP "..(?=%)") +>>>>>>> de29d3a... Add minor updates + +if grep -q "Discharging" <(echo "$output"); then + remaining_time=$(echo "$output" | grep -oP "..:..(?=:.. remaining)") + if [[ $charge -lt 20 ]]; then + icon="" + color="#FF0000" + elif [[ $charge -lt 40 ]]; then + icon="" + color="#FFAE00" + elif [[ $charge -lt 60 ]]; then + icon="" + color="#FFF600" + elif [[ $charge -lt 80 ]]; then + icon="" + color="#A8FF00" + else + icon="" + color="#00FF00" + fi +else + icon= + color="lightblue" +fi + +echo "<span color='$color'>$icon</span> $charge% ($remaining_time)" +echo "$icon $charge% ($remaining_time)" |