From: Christian Heller Date: Wed, 12 Mar 2025 01:35:12 +0000 (+0100) Subject: Improve battery status. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/do_day?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=config Improve battery status. --- diff --git a/testing/home/t490s/.nonpath_bins/status.sh b/testing/home/t490s/.nonpath_bins/status.sh index 256d9c0..f65d1df 100755 --- a/testing/home/t490s/.nonpath_bins/status.sh +++ b/testing/home/t490s/.nonpath_bins/status.sh @@ -1,11 +1,34 @@ #!/bin/sh # see sway-bar(5) and swaybar-protocol(7) KILO=1000 + +BAT_DIR=/sys/class/power_supply/BAT0 + +print_battery () { + COLOR=ffffff + printf ' {"separator_block_width": 20, "full_text": "' + STATUS=$(cat "${BAT_DIR}/status") + if [ "${STATUS}" = "Not charging" ]; then + printf "_" + elif [ "${STATUS}" = "Charging" ]; then + printf "^" + COLOR=00ff00 + elif [ "${STATUS}" = "Discharging" ]; then + printf "v" + COLOR=ffff00 + else + printf "?" + fi + printf ":%d" $(calc "100 * $(cat ${BAT_DIR}/energy_full) // $(cat ${BAT_DIR}/energy_full_design)") + printf ":%d" $(calc "100 * $(cat ${BAT_DIR}/energy_now) // $(cat ${BAT_DIR}/energy_full)") + printf '", "color": "%s"},\n' "${COLOR}" +} + printf '{ "version": 1 }\n[\n' while true; do printf ' [\n' printf ' {"separator_block_width": 20, "full_text": "%s"},\n' "$(ip -4 addr show scope global | grep -oP '(?<=inet\s)\d+(\.\d+){3}')" - printf ' {"separator_block_width": 20, "full_text": "%s"},\n' "$(cat /sys/class/power_supply/BAT0/status)" + print_battery printf ' {"separator_block_width": 20, "full_text": "%d° C"},\n' $(calc "$(cat /sys/class/thermal/thermal_zone0/temp) // ${KILO}") printf ' {"separator_block_width": 20, "full_text": "%s"},\n' "$(date +'%Y-%m-%d %H:%M:%S/%Z')" printf ' ],\n'