From 5c81014bdd9124bc5387f6fc8d6d48936b12d7af Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 12 Mar 2025 02:35:12 +0100 Subject: [PATCH] Improve battery status. --- testing/home/t490s/.nonpath_bins/status.sh | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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' -- 2.30.2