-
Notifications
You must be signed in to change notification settings - Fork 0
Using Fortune
Some tips for using the fortune command.
Install fortune on macOS
$ brew install fortune
Or a linux like Ubuntu
$ sudo apt install fortune
You can see where fortune installs its files by default by running the following command:
$ fortune -f
Install some other tools to liven things up.
$ brew install cowsay lolcat
Then combine all of them for some fun output like this:
$ fortune seinfeldtoday | cowthink -n -d | lolcat -a -s 40
The fortune program typically comes with a set of fortunes, and you can install more.
You can also just create your own with augury
and place them into a folder.
So for instance, if we created a folder in our home dir:
$ mkdir ~/.fortunes
Then created some fortune files in there:
$ augury generate -c 0 seinfeldtoday ~/.fortunes/seinfeldtoday
$ augury generate -c 0 -l --remove-links shituserstories ~/.fortunes/shituserstories
Then you can run fortune
with just those files:
$ fortune -f ~/.fortunes
100.00% /Users/claytron/.fortunes
10.91% shituserstories
89.09% seinfeldtoday
This is the whole reason we are here folks. I've had fortune running in my shell startup for years.
Let's add on from the example above.
Put something like this in your ~/.bash_profile
or ~/.zprofile
and you'll always have a laugh when you open a new terminal.
The file you put this in is dependent on your shell and terminal, but that's outside the scope of this wiki.
function makeMeLaugh() {
[ $(which fortune) ] || return 0
local output
if [ -d "$HOME/.fortunes" ]; then
# Evenly pick from our fortunes
output=$(fortune -e "$HOME/.fortunes")
else
# Otherwise any fortune will do
output=$(fortune)
fi
# If cowsay is installed, have a dead cow think the fortune at the
# default width set in augury of 72
if [ $(which cowthink) ]; then
output=$(cowthink -d -W 72 $output)
fi
# Add a bit of padding and show in the terminal.
# Make it really fancy with lolcat or just print it out.
if [ $(which lolcat) ]; then
echo -e "\n$output\n" | lolcat -a -s 80
else
echo -e "\n$output\n"
fi
}
# Call it to output to the terminal
makeMeLaugh