Good fortune
October 2, 2022 at 12:55 PM by Dr. Drang
I don’t want this to turn into the “obscure Unix commands blog” (any more than it already is), but I did have reason to use another old Unix command the other day. Unlike rs
, this one is one that I’d used a lot in the past but hadn’t done anything with in ages.
The command is fortune
, and I got reacquainted with it as a result of this question in the Keyboard Maestro forums. The OP wanted a way to display random messages from a list he’d made. This is exactly what fortune
is for, so I suggested he use it. He didn’t follow my suggestion, which I think has more to do with the fear some people have of the command line than of fortune
’s value.
Apple doesn’t include fortune
with macOS, so you have to install it yourself, with Homebrew being the easiest way to do so. With fortune
on your system, you then have to create a text file with all of the messages you want to select from, save that file to a specific folder, and run a simple command that creates a lookup table that fortune
uses. See this writeup by Louis Tiao for full details. The only adjustment I have to Louis’s instructions is that if you’re using an Apple Silicon Mac, the folder you put your list of messages in should be
/opt/homebrew/share/games/fortunes
instead of
/usr/local/share/games/fortunes
This is in keeping with Homebrew’s new defaults for Apple Silicon.
fortune
comes with several files of aphorisms, but I don’t recommend you use any of them. They suffer from two problems:
- First, too many cooks. Lots of people have contributed to the files, so you get too wide a variety of subject matter and taste.
- Second, most of the cooks seem to have been boys in their teens and early twenties, i.e., people who have no taste.
About 20 years ago, I used fortune
to generate random email signatures (which was the style at the time). One of the aphorism lists I used was the Oblique Strategies suggestions by Brian Eno and Peter Schmidt. I don’t remember where I got them, but it was likely this page, which goes back to the late 90s.
The strategies had to be reformatted like this, with each saying followed by a line with just a percentage sign:
Abandon normal instruments
%
Accept advice
%
Accretion
%
A line has two sides
%
Allow an easement (an easement is the abandonment of a stricture)
%
This file, named oblique
with no extension, was saved in the appropriate folder on my Linux system. I then ran
strfile oblique
to create create the oblique.dat
file. From the strfile
man page:
strfile reads a file containing groups of lines separated by a line containing a single percent `%’ sign (or other specified delimiter character) and creates a data file which contains a header structure and a table of file offsets for each group of lines. This allows random access of the strings.
Now fortune oblique
returns lines like
Look at the order in which you do things
Always good advice.