testsAndMisc/linux_configuration/scripts/periodic_background/i3-configuration/i3blocks/volume.sh
Krzysztof kuhy Rudnicki db6276b3ff refactor(linux_configuration): move remaining dirs + scripts/ to meta/
- Move fresh-install/ → scripts/single_use/fresh-install/
- Move hosts/ → scripts/periodic_background/hosts/
- Move i3-configuration/ → scripts/periodic_background/i3-configuration/
- Delete linux_configuration/LaTeX/, nix-poc/, report/ (dead dirs)
- Move repo-root scripts/ → meta/scripts/
- Update root .pre-commit-config.yaml: scripts/ → meta/scripts/ (9 entries)
- Update run.sh ARTIFACT_INIT_SCRIPT to meta/scripts/
- Update fresh-install/main.sh: hosts/install.sh + i3-configuration/install.sh paths
- Update check_python_location.sh: add meta/scripts/ to exception list
- Fix midnight flakiness in test_recent_workout_returns_true: use timezone-aware
  local noon instead of now-1h to avoid SQL date() boundary issues
2026-05-15 00:53:01 +02:00

44 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# i3blocks persist-mode volume indicator.
#
# Event-driven: blocks in `read` on the `pactl subscribe` event stream.
# No sleep, no polling loop, no awk/tr/grep forks. One pactl-subscribe
# process stays alive; two short pactl calls run only on actual events.
#
# Configure with `interval=persist` and `markup=pango` in the i3blocks
# config. In persist mode each newline is a separate status update, so
# we emit exactly ONE line (with inline pango markup for color).
set -u
GREEN='#50FA7B'
RED='#FF5555'
emit() {
local raw mute vol icon color
raw=$(pactl get-sink-volume @DEFAULT_SINK@ 2> /dev/null) || return 0
if [[ $raw =~ ([0-9]+)% ]]; then
vol=${BASH_REMATCH[1]}
else
vol=0
fi
mute=$(pactl get-sink-mute @DEFAULT_SINK@ 2> /dev/null) || return 0
if [[ $mute == *yes ]]; then
icon='🔇'
color=$RED
else
icon='🔊'
color=$GREEN
fi
printf '<span color="%s">%s %s%%</span>\n' "$color" "$icon" "$vol"
}
emit
# `read -r` blocks on the event stream — no busy-wait, no sleep.
pactl subscribe 2> /dev/null | while read -r line; do
[[ $line == *"on sink"* || $line == *"on server"* ]] || continue
emit
done