Weather&Audio

This commit is contained in:
soraefir
2026-06-13 12:19:46 +02:00
parent 58af37ea8c
commit 43a074f355
8 changed files with 246 additions and 9 deletions

View File

@@ -0,0 +1,33 @@
#!/usr/bin/env bash
volicons=("󰕿" "󰖀" "󰕾")
vol() { wpctl get-volume @DEFAULT_AUDIO_"$1"@ | awk '{print int($2*100)}'; }
ismuted() { wpctl get-volume @DEFAULT_AUDIO_"$1"@ | rg -qi muted; echo -n $?; }
setvol() { wpctl set-volume @DEFAULT_AUDIO_"$1"@ "$(awk -v n="$2" 'BEGIN{print n/100}')"; }
setmute() { wpctl set-mute @DEFAULT_AUDIO_"$1"@ toggle; }
gen_output() {
percent=$(vol "SINK")
lvl=$(awk -v n="$percent" 'BEGIN{print int(n/34)}')
sink_muted=$(ismuted "SINK")
source_muted=$(ismuted "SOURCE")
[ "$sink_muted" = 0 ] && icon="󰝟" || icon="${volicons[$lvl]}"
[ "$source_muted" = 0 ] && mic_icon="󰍭" || mic_icon="󰍬"
printf '{"icon":"%s","percent":%s,"sink_muted":%s,"mic_icon":"%s","microphone":%s,"source_muted":%s}\n' \
"$icon" "$percent" "$([ "$sink_muted" = 0 ] && echo true || echo false)" \
"$mic_icon" "$(vol SOURCE)" "$([ "$source_muted" = 0 ] && echo true || echo false)"
}
case "$1" in
mute) setmute "$2" ;;
setvol) setvol "$2" "$3" ;;
*)
gen_output
pw-cli -m 2>/dev/null | rg --line-buffered "PipeWire:Interface:Client" | while read -r _; do
gen_output
done
;;
esac