Show battery status in sway bar

This commit is contained in:
KK
2026-06-26 00:05:57 +02:00
parent 9fd1ba70a3
commit ac1005b842
2 changed files with 20 additions and 10 deletions

View File

@@ -7,21 +7,28 @@ print_status() {
brightness=$(brightnessctl -m 2>/dev/null | awk -F, '{print $4}')
voxtype_state=$(voxtype status 2>/dev/null)
case "$voxtype_state" in
recording) voxtype=' | VOX REC' ;;
transcribing) voxtype=' | VOX ...' ;;
*) voxtype='' ;;
esac
battery_device=$(upower -e 2>/dev/null | grep -m 1 battery)
if [ -n "$battery_device" ]; then
battery=$(upower -i "$battery_device" 2>/dev/null | awk '
/state/ { state=$2 }
/percentage/ { percentage=$2 }
END {
if (percentage != "") {
printf "%s", percentage
if (state != "") printf " %s", state
}
}
')
fi
printf 'VOL %s | BRI %s%s | %s\n' "${volume:-n/a}" "${brightness:-n/a}" "$voxtype" "$(date +'%Y-%m-%d %H:%M:%S')"
printf 'VOL %s | BRI %s | BAT %s | %s\n' "${volume:-n/a}" "${brightness:-n/a}" "${battery:-n/a}" "$(date +'%Y-%m-%d %H:%M:%S')"
}
trap print_status USR1
print_status
while :; do
sleep 1 &
sleep 60 &
wait $!
print_status
done