#!/bin/bash
#                       /usr/local/bin/audition
#  http://crystalfaeries.net/posix/bin/audition
# celeste:crystalfaery 2016-02-10 04:28:22+00:00
# open the smallest audacity project from our archive we have not auditioned

# CONFIGURATION
audirectory=/home/.audacity			# where we keep audacity projects
audprojects="$audirectory"/.projects.txt	# where we track auditions
if [ ! -s $audprojects ]
then	# unless we have an existing to do list, generate a new one:
	du "$audirectory"/*.aup |  sort -n | cut -f2- > $audprojects
fi
while [ -s $audprojects ]
do	# iterate our to do list
	audproject="$(	head -n  1	$audprojects)"
			tail -n +2	$audprojects >	/tmp/$$.txt
	mv						/tmp/$$.txt \
					$audprojects
			  audata="$(echo $audproject|sed 's/\.aup$/_data/')"
	echo	"OPENING $audata"		>&2
	audacity "$audproject" && read -p "DELETE $audata ? " REPLY || exit $?
	firstchar="$(echo "$REPLY" | sed 's/^Y/y/ ; s/^y.*$/y/')" # accept Y* or y*
	if [ "$firstchar" = "y" ]
	then	# user requested delete
		delete -r "$audproject" "$audata"	\
		&& echo	"DELETED $audata" 	>&2	\
		|| echo	"KEEPING $audata"	>&2
	else	# user declined to delete
		echo	"KEEPING $audata"	>&2
	fi
done


syntax highlighted by Code2HTML, v. 0.9.1