function showHelp
{
- echo "Plays mp3 files in all subdirectories."
- echo "Usage: ./mp-play.sh [-h|--help] [-R|--random] [-r|--repeat] "
- echo " [-a|-recursive] [--reverse] [--time]"
- echo " [--remove] [-q|--quiet] [-v|--verbose] [DESTINATION]"
+ echo "Usage: $0 [-h|--help]"
+ echo " $0 [OPTIONS] [--] [DESTINATIONS]"
echo ""
- echo "Options:"
- echo " --time sort by age of file"
- echo " -R, --random randomize files"
- echo " -r, --repeat repeat playing infintely"
+ echo "OPTIONS:"
echo " -a, --recursive recursively find files to play"
- echo " --reverse reverse playing order"
- echo " --remove ask to remove played files after playing"
+ echo " -h, --help show this message"
echo " -q, --quiet do not produce output when playing"
- echo " -v, --versbose produce more output"
+ echo " -r, --repeat repeat playing infintely"
+ echo " -R, --random randomize files"
+ echo " --remove ask to remove played files after playing"
+ echo " --reverse reverse playing order"
+ echo " --time sort by age of file"
+ echo " -v, --verbose produce more output"
}
+if ! options=$(getopt -u -o hRravq -l time,random,repeat,recursive,reverse,remove,quiet,verbose -- "$@")
+then
+ showHelp >&2
+ exit 1
+fi
+set -- $options
+
#Parse the arguments
while [ $# -gt 0 ]
do
--remove) optRemove=1 ;;
--reverse) optReverse=1 ;;
--time) optSorttime=1 ;;
+ --) shift; break ;;
+ -*) echo "Unrecognized option $1" >&2; showHelp >&2; exit 1 ;;
*) break ;;
esac
shift
else
maxlevel=1
fi
-
+
# Create playlist
find "$@" -maxdepth $maxlevel -type f \