diff options
| author | Skladnayazebra <skladnayazebra@gmail.com> | 2025-11-07 18:46:58 +0100 |
|---|---|---|
| committer | Skladnayazebra <skladnayazebra@gmail.com> | 2025-11-07 18:46:58 +0100 |
| commit | 56ae7e967f38851eab8f1340ef5c8550b03c3d5f (patch) | |
| tree | 4f3c61b9403b21dd7569bac37a2c039ab08c877f /tmux | |
| parent | d8b1c2acd66eabf64c2de0ac3e09ca199875b762 (diff) | |
Add charging icon and only show estimate when on bat power
Diffstat (limited to 'tmux')
| -rwxr-xr-x | tmux/battery.sh | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/tmux/battery.sh b/tmux/battery.sh index 62e0b32..96ca839 100755 --- a/tmux/battery.sh +++ b/tmux/battery.sh @@ -4,33 +4,44 @@ round() { awk -v n=$1 -v d=$2 'BEGIN{print int((n+d/2)/d) * d}'; } 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)}') + +# charging / discharging / pending-charge +chg_state=$(upower -i /org/freedesktop/UPower/devices/DisplayDevice | awk '/state:/ {print $2}') + # 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]"; +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 +if [[ $chg_state == "charging" ]]; then + printf "" +else + 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 +fi + printf " "; # percentage level rounded to a whole number (69%) printf "%.0f%%" "${percentage_raw%%%}"; -printf " "; -# estimated time on battery -printf " $est_time" +if [[ $est_time ]]; then + printf " "; + # estimated time, if on battery + printf " $est_time" +fi printf " "; # reset style printf "#[default]"; |
