From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 12 Mar 2025 01:35:12 +0000 (+0100)
Subject: Improve battery status.
X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/tasks?a=commitdiff_plain;h=5c81014bdd9124bc5387f6fc8d6d48936b12d7af;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'