diff options
Diffstat (limited to 'i3/.config/i3blocks/bin/battery')
-rwxr-xr-x | i3/.config/i3blocks/bin/battery | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/i3/.config/i3blocks/bin/battery b/i3/.config/i3blocks/bin/battery index d475741..7c7d76c 100755 --- a/i3/.config/i3blocks/bin/battery +++ b/i3/.config/i3blocks/bin/battery @@ -5,35 +5,45 @@ if [ ! -d /sys/class/power_supply/BAT0 ]; then exit fi -output="$(acpi -b)" -remaining_time=$(echo "$output" | grep -o "[0-9][0-9]:[0-9][0-9]") -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 "..(?=%)") - -if grep -q "Discharging" <(echo "$output"); then - remaining_time=$(echo "$output" | grep -oP "..:..(?=:.. remaining)") - if [[ $charge -lt 20 ]]; then +current_now=$(cat /sys/class/power_supply/BAT0/current_now) +charge_now=$(cat /sys/class/power_supply/BAT0/charge_now) +charge_full=$(cat /sys/class/power_supply/BAT0/charge_full) +bat_status=$(cat /sys/class/power_supply/BAT0/status) +charge_percent=$(( (100*charge_now) / charge_full )) + +if [ "$bat_status" = "Full" ]; then + echo "<span color='gray'></span> Full" && exit +fi + +if [ "$bat_status" = "Discharging" ]; then + tot_minutes_remaining=$(( charge_now*60/current_now )) + + if [[ $charge_percent -lt 20 ]]; then icon="" color="#FF0000" - elif [[ $charge -lt 40 ]]; then + elif [[ $charge_percent -lt 40 ]]; then icon="" - color="#FFAE00" - elif [[ $charge -lt 60 ]]; then + color='gray' # ="#FFAE00" + elif [[ $charge_percent -lt 60 ]]; then icon="" - color="#FFF600" - elif [[ $charge -lt 80 ]]; then + color='gray' # ="#FFF600" + elif [[ $charge_percent -lt 80 ]]; then icon="" - color="#A8FF00" + color='gray' # ="#A8FF00" else icon="" - color="#00FF00" + color='gray' # ="#00FF00" fi -else - icon= + +elif [ "$bat_status" = "Charging" ]; then + tot_minutes_remaining=$(( (charge_full-charge_now)*60/current_now )) + + icon= color="lightblue" fi -echo "<span color='$color'>$icon</span> $charge% ($remaining_time)" -echo "$icon $charge% ($remaining_time)" +time_remaining=$(printf "%02d:%02d" \ + $(( tot_minutes_remaining/60 )) \ + $(( tot_minutes_remaining/60 ))) + +echo "<span color='$color'>$icon</span> $charge_percent% ($time_remaining)" |