A set of POSIX* shell scripts designed for personal use. No guarantees when it comes to quality, as these are also used for various minor experiments of mine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
941 B

#!/bin/sh
# Grab a number that is greater than zero but no greater than the number of
# files in our directory
rand_file()
{
x=$(($(/usr/bin/dd bs=2 count=1 if=/dev/random of=/dev/stdout| /usr/bin/od -|\
/usr/bin/sed 's/ */ /'|/usr/bin/cut -d ' ' -f2|/usr/bin/sed 1!d)%$((1+$(/usr/bin/ls|\
/usr/bin/wc -l)))))
/usr/bin/echo "${x}"
}
if [ $# = 0 ]
then /usr/bin/printf "FPM provides a convenient way to use ffplay for audio playback.\nIt accepts the following arguments:\n\n-s: Shuffle songs in the directory randomly.\n\n-l: Play on repeat.\n\n"
else
case "$@" in
-s)
file=$(x=$(rand_file);if [ "${x}" = 0 ];then x=1;fi;/usr/bin/ls|sed "${x}"!d)
/usr/bin/ffplay -autoexit -nodisp "${file}"
sleep 1 # Prevent fpm from continuously respawning on kill
;;
-l)
while true
do /usr/bin/ffplay -autoexit -nodisp "$1"
done
;;
*)
/usr/bin/ffplay -autoexit -nodisp "$1"
;;
esac
fi
exit