diff options
| author | Skladnayazebra <skladnayazebra@gmail.com> | 2025-11-07 17:39:36 +0100 |
|---|---|---|
| committer | Skladnayazebra <skladnayazebra@gmail.com> | 2025-11-07 17:39:36 +0100 |
| commit | d8b1c2acd66eabf64c2de0ac3e09ca199875b762 (patch) | |
| tree | dfb653497ec28475464aad7fc748a4dbf737fa2f /tmux/battery.sh | |
| parent | 7dc3a6c9fb6fba9d19d305c4427e8fa7ceb61808 (diff) | |
Refactor battery indicator, add estimated time
Diffstat (limited to 'tmux/battery.sh')
| -rwxr-xr-x | tmux/battery.sh | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/tmux/battery.sh b/tmux/battery.sh index 2cd1afb..62e0b32 100755 --- a/tmux/battery.sh +++ b/tmux/battery.sh @@ -1,29 +1,36 @@ round() { awk -v n=$1 -v d=$2 'BEGIN{print int((n+d/2)/d) * d}'; } -upower -i /org/freedesktop/UPower/devices/DisplayDevice | awk '/percentage:/ {print $2}' | { - read percentage_raw; # e.g. 69.420% - percentage_10s=$(round "${percentage_raw%%%}" 10); # rounded number: 70 - # when battery is low, highlight it - if [ $percentage_10s -le "10" ]; then - printf "#[bg=red,fg=brightwhite]"; - elif [ $percentage_10s -le "20" ]; then - printf "#[bg=brightyellow]"; - fi - printf " "; - # icon - if [ $percentage_10s -le "10" ]; then printf ""; fi - if [ $percentage_10s -eq "20" ]; then printf ""; fi - if [ $percentage_10s -eq "30" ]; then printf ""; fi - if [ $percentage_10s -eq "40" ]; then printf ""; fi - if [ $percentage_10s -eq "50" ]; then printf ""; fi - if [ $percentage_10s -eq "60" ]; then printf ""; fi - if [ $percentage_10s -eq "70" ]; then printf ""; fi - if [ $percentage_10s -eq "80" ]; then printf ""; fi - if [ $percentage_10s -eq "90" ]; then printf ""; fi - if [ $percentage_10s -eq "100" ]; then printf ""; fi - printf " "; - # percentage level rounded to a whole number (69%) - printf "%.0f%%" "${percentage_raw%%%}"; - printf " "; - printf "#[default]"; # reset style -} +# e.g. 69.420% +percentage_raw=$(upower -i /org/freedesktop/UPower/devices/DisplayDevice | awk '/percentage:/ {print $2}') +# e.g. 7h +est_time=$(upower -i /org/freedesktop/UPower/devices/DisplayDevice | awk '/time to empty:/ {print $4substr($5, 1, 1)}') +# rounded to tens: 10 20 30 etc. +percentage_10s=$(round "${percentage_raw%%%}" 10); + +# when battery is low, highlight it +if [ $percentage_10s -le "10" ]; then + printf "#[bg=red,fg=brightwhite]"; +elif [ $percentage_10s -le "20" ]; then + printf "#[bg=brightyellow]"; +fi +printf " "; +# icon +if [ $percentage_10s -le "10" ]; then printf ""; fi +if [ $percentage_10s -eq "20" ]; then printf ""; fi +if [ $percentage_10s -eq "30" ]; then printf ""; fi +if [ $percentage_10s -eq "40" ]; then printf ""; fi +if [ $percentage_10s -eq "50" ]; then printf ""; fi +if [ $percentage_10s -eq "60" ]; then printf ""; fi +if [ $percentage_10s -eq "70" ]; then printf ""; fi +if [ $percentage_10s -eq "80" ]; then printf ""; fi +if [ $percentage_10s -eq "90" ]; then printf ""; fi +if [ $percentage_10s -eq "100" ]; then printf ""; fi +printf " "; +# percentage level rounded to a whole number (69%) +printf "%.0f%%" "${percentage_raw%%%}"; +printf " "; +# estimated time on battery +printf " $est_time" +printf " "; +# reset style +printf "#[default]"; |
