#!/usr/bin/env bash
F_NUM=$(($RANDOM % $(ls ~/.git/sounds/$i| wc -l)))
n=0
for i in *
do
if [[ n -eq $F_NUM ]]
then
afplay ~/.git/sounds/$i > /dev/null 2>&1 &
fi
n=$((n + 1))
done
SOUNDPATH=${HOME}/.play-random/sounds
if [ ! -d ${SOUNDPATH} ]; then
echo "Create and populate '${SOUNDPATH}' directory"
exit 1;
fi
SOUNDS=($(ls "${SOUNDPATH}"))
NUM_SOUNDS=${#SOUNDS[*]}
if [ ${NUM_SOUNDS} -eq 0 ]; then
echo "No sound files found in '${SOUNDPATH}' directory"
exit 1;
fi
# select which sound to play
SOUND="${SOUNDPATH}/${SOUNDS[$((RANDOM%NUM_SOUNDS))]}"
echo ${SOUND}
/usr/bin/aplay ${SOUND}