#!/bin/bash

# because firefox open and don't close sink inputs !
#
# so this tool is to be run in a daemon mode, where
# it clean the first oldest entries.. (roughly, depending
# of pacmd output), but do the job

# issues:
#  if you have multiple youtube webpage open, only the last will rest!

if [ $(pacmd list-sink-inputs| grep -c index:) -gt 1 ]; then
	indexlist=$( pacmd list-sink-inputs | grep index: | sed -e 's/.*index://' | tr '\n' ' ' | sed -e 's/^ //' -e 's/ $//' | rev | cut -d\  -f2- | rev )
	for index in $indexlist; do
		pacmd kill-sink-input $index
	done
fi

