POSIX_Scripts/fpm

39 lines
941 B
Bash
Executable File

#!/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