#!/usr/bin/env bash if [ ! -d /sys/class/power_supply/BAT0 ]; then echo " No battery" exit fi 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 " 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_percent -lt 40 ]]; then icon="" color='gray' # ="#FFAE00" elif [[ $charge_percent -lt 60 ]]; then icon="" color='gray' # ="#FFF600" elif [[ $charge_percent -lt 80 ]]; then icon="" color='gray' # ="#A8FF00" else icon="" color='gray' # ="#00FF00" fi elif [ "$bat_status" = "Charging" ]; then tot_minutes_remaining=$(( (charge_full-charge_now)*60/current_now )) icon= color="lightblue" fi time_remaining=$(printf "%02d:%02d" \ $(( tot_minutes_remaining/60 )) \ $(( tot_minutes_remaining - (tot_minutes_remaining/60)*60 ))) echo "$icon $charge_percent% ($time_remaining)"