From 422f41bc5522ae752c14a8cb63f87e0ac2ac2f27 Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Fri, 12 Dec 2014 19:07:56 -0800 Subject: [PATCH] stream: Fallback to whatever's playing when no source is asked for ... and Spotify can't be found. This requires even less thinking to bounce audio over to the speakers! --- stream | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/stream b/stream index 5911662..ceaf66b 100755 --- a/stream +++ b/stream @@ -16,13 +16,28 @@ case "$dst" in vol=$1 ;; *) - src=${1:-spotify} - shift - inputidx=$(find-sink-input "$src" | head -n1) + src=$1 + src_default=spotify + + # Find the source asked for, or our default if none was asked for. Set + # src to how we found the input, if we found it. + inputidx=$(find-sink-input "${src:-$src_default}") + [[ -n $inputidx ]] && src=${src:-$src_default} + + # If nothing was asked for and we couldn't find the default either, see + # if there are *any* inputs available. Set our src to distinguish it's + # fallback status in messages. + if [[ -z $inputidx && -z $src ]]; then + inputidx=$(find-sink-input) + src="whatever's playing" + fi + + # Still found nothing! if [[ -z $inputidx ]]; then - echo Unable to find sink input index for $src + echo "Unable to find sink input index for $src" exit 1 fi + shift ;; esac