#!/bin/sh
set -eu

# This script assumes that at most 2 sinks exist at any time.
# When this premise is no longer true, it needs to be upgraded.

CURRENT="$(pacmd list-sinks | grep '\* index' | cut -d: -f2 | tr -d ' ')"
OTHER="$(pacmd list-sinks | grep index | grep -v '\* index' | tail -n1 | cut -d: -f2 | tr -d ' ')"

if [ "$CURRENT" = 0 ]; then
	pacmd set-default-sink "$OTHER"
else
	pacmd set-default-sink 0
fi
