From 14e200f9b32521b356cf483da2c3d86c1070e138 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Sun, 15 Oct 2023 10:07:17 +0200 Subject: [PATCH] show correct charging/discharging emoji, not 3/4 all the time --- .local/bin/statusbar/sb-battery | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.local/bin/statusbar/sb-battery b/.local/bin/statusbar/sb-battery index fe7b5cf..3069c08 100755 --- a/.local/bin/statusbar/sb-battery +++ b/.local/bin/statusbar/sb-battery @@ -27,22 +27,29 @@ do printf '\n' && continue - status=$(sed "s/Discharging//;s/Not charging/🛑/;s/Charging/🔌/;s/Unknown/🔋/;s/Full/⚡/" "$battery"/status) + unset status + status=$(sed "s/Not charging/🛑/" "$battery"/status) # Center picture around the actual capacity. # Displayable capacities: 0, 1/4, 1/2, 3/4, 1 -> intervall of length 25% centered around displaycategory # -> +- 12.5% for every level - if [ "$status" = "" ]; then - [ "$capacity" -le 13 ] && - status="" - [ "$capacity" -le 37 ] && - status="" - [ "$capacity" -le 63 ] && - status="" + if grep -qE "(Discharging|Charging)" "$battery"/status; then + status= [ "$capacity" -le 87 ] && status="" + [ "$capacity" -le 63 ] && + status="" + [ "$capacity" -le 37 ] && + status="" + [ "$capacity" -le 13 ] && + status="" + [ "$capacity" -le 5 ] && + status="❗" + if grep -q "Charging" "$battery"/status; then + status="${status}🔌" + fi fi - printf "%s\n" "$status" + printf "%s \n" "$status" else echo "Error. Capacity:$capacity" > /dev/stderr #if battery fails during reading, quit fi -done | sed 's/ *$//' +done