Blog: Fortune

Fortune

Fortune is a Unix/Linux program that will generate a pseudo random fortune / quote from a text based database. Fortune comes with several databases by default that are of no real interest to me. My interest in fortune is the ability to create and use your own databases. Rather than having a fortune come up I wanted a quote from a church father to come up.

Creating a database with quotes from the church fathers is a two step process.

The first step is is to create an Linux/Unix based text file with quotes that you want to you use. Between each quote there should be a single line with a single %

An example being:

Affliction was allowed to make those afflicted more careful and more pious.
--Saint John Chrysostom
%
What rain is for seeds tears are for those who are afflicted…
--Saint John Chrysostom

Once you save your file run the following command from the terminal in the directory your file is located

strfile YourTextFile

This will create YourTextFile.dat

If you type fortune /pathtoyourfile/YourTextFile

A "fortune" in this case a saying from the Church Fathers will be generated at the command line. You can pipe this into other programs such as cowsay or xcowsay. I added to my .zshrc file so every time I start a new terminal I get a saying of a church father. I also created an alias for clear so every time I clear my terminal I get a saying from a church father. You can create a simple script that pipes fortune into xcowsay or notify-file to get a popup in your xwindow session based on either an action or based on a time frame. There is a php version of fortune that allows you to add random sayings to your website.