Skip to content

Instantly share code, notes, and snippets.

@nhomble
Last active August 29, 2015 14:01
Show Gist options
  • Save nhomble/3ebeb588734d393b2928 to your computer and use it in GitHub Desktop.
Save nhomble/3ebeb588734d393b2928 to your computer and use it in GitHub Desktop.
bored at the airport... when my brother is around we play this game
#!/usr/bin/env bash
SOURCE=$1
if [ -z "$SOURCE" ]; then
echo "I need the source directory"
exit
fi
if [ ! -d "$SOURCE" ]; then
echo "You did not give me a directory"
exit
fi
i=0
songs=[]
OIFS=$IFS
IFS=$'\n'
for song in $(find "$SOURCE" -type f -iregex '.*\(mp3\|wav\)'); do
songs[$i]="$song"
let i+=1
done
if [ $i -lt 4 ]; then
echo "not enough songs..."
exit
fi
IFS=$OIFS
guess=[]
while true; do
# yeah... not so clean
index1=$(($RANDOM % $i))
index2=$(($RANDOM % $i))
while [ $index1 -eq $index2 ]; do
index2=$(($RANDOM % $i))
done
index3=$(($RANDOM % $i))
while [ $index1 -eq $index3 ] || [ $index2 -eq $index3 ]; do
index3=$(($RANDOM % $i))
done
index4=$(($RANDOM % $i))
while [ $index1 -eq $index4 ] || [ $index2 -eq $index4 ] || [ $index3 -eq $index4 ]; do
index4=$(($RANDOM % $i))
done
guess[0]=${songs[$index1]}
guess[1]=${songs[$index2]}
guess[2]=${songs[$index3]}
guess[3]=${songs[$index4]}
toPlay=$(($RANDOM % 4))
mplayer -quiet "${guess[$toPlay]}" &> /dev/null &
echo "CHOICE 1: $(basename "${guess[0]}")"
echo "CHOICE 2: $(basename "${guess[1]}")"
echo "CHOICE 3: $(basename "${guess[2]}")"
echo "CHOICE 4: $(basename "${guess[3]}")"
ANSWER=""
while [ -z $ANSWER ]; do
read ANSWER
done
let toPlay+=1
if [ $ANSWER -eq $toPlay ]; then
echo "YOU GOT IT"
else
echo "WRONG"
echo "ANSWER IS: $(basename "${guess[$(($toPlay - 1))]}")"
echo ""
fi
pkill mplayer
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment