Make Your Own Fortune
As we all go about our day we discover bits of wisdom that WOW! and YES! seem to be directed at you.
I like to put these bits together in a file for later review. Using the programs fortune and cowsay and lolcat I made a little shell script that runs at a console login or when a terminal window/tab is opened and outputs a colourful, random fortune from my custom collection.
Fortune
The fortune command is included in the FreeBSD base system. On other BSDs and Linuxes its usually available to install as the fortune or fortune-mod package.
Running fortune all command prints an adage chosen at random from database files stored (on FreeBSD) in /usr/share/games/fortune:
-> fortune all
To see the last 10 lines of a long file, use "tail filename". To see the
first 10 lines, use "head filename". To see new lines as they're appended
to a file, use "tail -f filename".
-- Dru <genesis@istar.ca>
Usually on a Linux system its a simple fortune or fortunes command:
-> fortune
I'll defend to the death your right to say that, but I never said I'd
listen to it!
-- Tom Galloway with apologies to VoltaireCustomize
Create the my_fortune file (I place mine in ~/.config):
vi ~/.config/my_fortune
Add blocks of text separated by the % percent symbol. Example:
All creatures love life. All creatures fear death. Therefore do not kill or help others to kill.
-- The Buddha
%
Everyone takes the limits of his own vision for the limits of the world.
-- Arthur Schopenhauer
%
Non est ad astra mollis e terris via (there is no easy way from the earth to the stars).
-- Seneca
%
Save changes and exit.
Convert this file to a format that fortune can use with the included strfile command, which generates the necessary *.dat file type:
strfile -c % ~/.config/my_fortune ~/.config/my_fortune.dat
NOTE
Both my_fortune and my_fortune.dat need to be located in the same directory.
Display your own fortune:
-> fortune ~/.config/my_fortune
The price of anything is the amount of life you exchange for it.
-- Henry David ThoreauCowsay
What is better than seeing your own fortune in the console? Why having a cow deliver it!
Install cowsay with your BSD or Linux package manager. On FreeBSD:
doas pkg install cowsay
Pipe your fortune to the cow:
-> fortune ~/.config/my_fortune | cowsay
_________________________________________
/ If you don’t get everything you want, \
| think of the things you don’t get |
| that you don’t want. |
\ -- Oscar Wilde /
---------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
I actually prefer my fortunes to be delivered by a kitty:
-> fortune ~/.config/my_fortune | cowsay -f kitty
_________________________________________
/ I have learned silence from the \
| talkative, toleration from the |
| intolerant, and kindness from the |
| unkind; yet strange, I am ungrateful to |
\ these teachers. -- Kahlil Gibran /
-----------------------------------------
\
\
("`-' '-/") .___..--' ' "`-._
` *_ * ) `-. ( ) .`-.__. `)
(_Y_.) ' ._ ) `._` ; `` -. .-'
_.. `--'_..-_/ /--' _ .' ,4
( i l ),-'' ( l i),' ( ( ! .-'Lolcat
How about a fortune delivered with a dash of colour, courtesy of lolcat? Its usually available as a package or can be installed as a Ruby gem.
On FreeBSD, install:
doas pkg install lolcat
Run:

Script
I created a shell script for these commands. It displays a colour cow-ified fortune if the system has lolcat + cowsay + fortune, falls back to the fortune cow if lolcat is missing, falls back to a plain fortune if cowsay is also missing, and errors out if no my_fortune file or fortune command is found.
Verify that $HOME/bin directory is present and in your PATH:
echo $PATH
The script, saved as my_fortune.sh and placed in ~/bin:
#!/bin/sh
#
# Purpose: Display a random fortune from my custom fortunes file
quote="$HOME/.config/my_fortune"
cowfile="kitty"
fort="command -v fortune"
cows="command -v cowsay"
lols="command -v lolcat"
if [ -f $quote ]; then
if $fort 2>&1 >/dev/null && $cows 2>&1 >/dev/null && $lols 2>&1 >/dev/null; then
fortune $quote | cowsay -f $cowfile | lolcat -f
elif $fort 2>&1 >/dev/null && $cows 2>&1 >/dev/null; then
fortune $quote | cowsay -f $cowfile
elif $fort 2>&1 >/dev/null; then
fortune $quote
else
echo "(O< error: script $0 requires: fortune; recommends: cowsay, lolcat"
echo "(/)_"
exit 1
fi
else
echo "(O< error: $quote not found."
echo "(/)_"
exit 1
fi
Make the script executable:
chmod 755 ~/bin/my_fortune.sh
Run:
my_fortune.sh
... to display your own jazzy fortune!
Auto-run
To have my_fortune.sh run whenever logging into a console or opening a terminal window/tab, add the script to the shell's config file.
I use the fish shell, and I modify the config.fish file:
vi ~/.config/fish/config.fish
Add:
if status is-interactive
if command -v my_fortune.sh > /dev/null
my_fortune.sh
end
end
Save changes and exit.
For bash, modify .bashrc:
vi ~/.bashrc
Add:
if command -v my_fortune.sh 2>&1 >/dev/null
then
my_fortune.sh
fi
Save changes and exit.
Modify as appropriate (.shrc for sh, etc) for your chosen shell.
Its a fun and often enlightening nudge to start the day!

You can like, share, or comment on this post on the Fediverse 💬
« Previous: Configure SSH on FreeBSD for Passwordless Logins to Servers