Skip to content

Instantly share code, notes, and snippets.

@insanity54
Last active December 31, 2016 22:21
Show Gist options
  • Select an option

  • Save insanity54/83550daec75f4ceb0482d78c668b5c87 to your computer and use it in GitHub Desktop.

Select an option

Save insanity54/83550daec75f4ceb0482d78c668b5c87 to your computer and use it in GitHub Desktop.
Fortune generator
#!/bin/bash
# Have a character tell you a fortune every n minutes
# Dependencies:
# - sed
# - shuf
# - sleep
# - fortune
# - cowsay
# configure how often the fortune should change (in seconds)
# prefer to use the command line argument, if there is one.
if [ -z $1 ]; then
interval=$((60*80)) # default to 80 minutes
else
interval=$1
fi
echo "displaying a new fortune every ${interval} seconds."
sleep 5
# every n minutes, display a new fortune
while ((1))
do
clear
# choose a random character from those available on the system
character=$(cowsay -l | sed '1d' | sed 's/ /\n/g' | shuf | sed -n '1p')
cowsay -f ${character} $(fortune)
sleep ${interval}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment