#!/usr/bin/bash
# ABOUTME: Walker-dmenu PulseAudio sink switcher using pactl.
# ABOUTME: Changes the default sink and moves all active streams to it.

# choose audio sink via rofi
# changes default sink and moves all streams to that sink

sink=$(pactl list sinks short | awk '{print $1, $2}' | walker -d -p "󱡫 Sink Switcher" | awk '{print $1}')

# Walker cancel returns empty — awk masks its non-zero exit. Guard here so we
# don't call `pactl set-default-sink ""` on dismissal.
[[ -n "$sink" ]] || exit 0

pactl set-default-sink "$sink" &&
for input in $(pactl list sink-inputs short | awk '{print $1}'); do
	pactl move-sink-input "$input" "$sink"
done
