profile picture

Using fortune to reinforce habits

July 23, 2025 - intermediate cli

A while ago I installed a bunch of new command-line tools, some of which replaced my existing tools, like eza instead of ls. Other tools improved the way that I work, such as LazyGit – the only interface to Git that I’ve found to be better that just using git commands.

If you’re looking for some recommendations for a modern command-line, I can highly recommend Supercharge your shell by Justin Mayer, or Oxidise your command line from the No Boilerplate YouTube channel. Many of these tools are written in Rust, which is a favourite language of mine, but that shouldn’t make much difference to you!

I had two problems though.

Problem 1: Forgetting to use the tools

One problem was that muscle-memory meant I kept using the old commands instead of the new ones. I could fix this by creating aliases, like alias ls=eza. That would mean that whenever I typed ls the command that actually was run would be eza. That’s fine with commands which are backwards compatible. eza supports all (or at least most!) of the flags that ls supports.

The problem was with commands that aren’t compatible. For example, the duf command is much more powerful than du which I used to use, and isn’t a drop-in replacement.

Problem 2: Forgetting I installed the tool

The other problem was that I kept forgetting that I had installed a tool, or if I remembered, then I couldn’t remember what the tool was called.

While I was working on this post, I couldn’t remember the name of the xh tool. It’s an HTTP client for the command line. It’s a replacement for HTTPie which was a replacement for Curl!

The Solution

I needed some constant reminders that these tools existed on my computer, and a reminder of what each tool did.

What I imagined was that every time I opened a terminal window, I would get a short message saying, “Don’t forget you’ve installed xh – it’s a command-line HTTP client!”

Yes, I really write messages to myself in that chirpy style.

In steps fortune, fortunately

I nearly started coding something in Python. I am a programmer after all. Then I remembered…

There’s a tool for managing a database of short text snippets, and selecting snippets at random. It’s called fortune and it’s a proper old-school UNIX utility.

These days, fortune isn’t usually installed by default on Linux. The following are the commands I know for installing fortune on different platforms:

# Debian etc.
apt install fortune-mod

# Fedora etc:
sudo dnf install fortune-mod

# Arch:
sudo pacman -S fortune-mod

# MacOS:
brew install fortune

Once it’s installed, you can see a random snippet by running the fortune command with no parameters. You’ll get a different snippet each time.

$ fortune
"Earth is a great, big funhouse without the fun."
        -- Jeff Berner

$ fortune
Honesty pays, but it doesn't seem to pay enough to suit some people.
        -- F.M. Hubbard

I suspect that most people who install fortune just use the data files that come with fortune, just like I did above. They contain a bunch of jokes, quotes, technical and philosophical observations.

But you can also create your own data files for fortune.

Create your own fortune file

I created a short text file called “habits”, and added some short snippets to it. The format isn’t very complicated. Each snippet is separated by the percent character (%) on its own line, like this:

Don't forget about hexyl! A handy binary file viewer.
%
Still using man? Try using *tldr* first!
%
Don't use *ps* - use *procs*!

Fortune can’t use this text file as it is. First, it needs a data (or “dat”) file to be created. The data file sits alongside the text file and contains information that allows fortune to look up a random snippet really quickly. Fortunately the tool that does this processing is packaged with fortune, and it’s called strfile.

To create a file called “habits.dat” from the file “habits”, I ran strfile habits habits.dat. This created “habits.dat” in my current directory. Now I can run fortune and point it at my text file. It will find the dat file automatically:

# Check that both habits and habits.dat are in the right place:
$ ls -1
habits
habits.dat

$ fortune habits
Still using man? Try using *tldr* first!

$ fortune habits
Don't forget about hexyl! A handy binary file viewer.

Make it easy to update the habits file

I often forget how to update the data file when I’ve updated my fortune text file. (I had actually forgotten when I started to write this post.) I created a Makefile to make it easier to update the data file. Makefiles are also pretty old-school, but they’re also the perfect tool for this job!

# Makefile

habits.dat: habits
	@strfile habits habits.dat

Just make sure your text editor isn’t going to replace the indent with spaces – it’s important that it remains a tab character.

I have to admit that my Makefile is slightly more complex than this, but I’m a nerd. The Makefile above is fine.

After writing this, I can now just run make, and it will update “habits.dat” if the “habits” file has changed.

At this point, I filled out my “habits” file with details of all the commands I’d installed. I stole some content from tldr, which is super-helpful for learning the basics for a new tool.

$ tldr duf

- List accessible devices:
    duf

- List everything (such as pseudo, duplicate or inaccessible file systems):
    duf --all

- Only show specified devices or mount points:
    duf path/to/directory1 path/to/directory2 ...

- Sort the output by a specified criteria:
    duf --sort size|used|avail|usage

    ...

Automatic reminders

Do you remember that I wanted to print out these snippets every time I opened a terminal window? How you do that depends on the shell you’re running.

First, I moved the directory containing “habits”, “habits.dat”, and my “Makefile” into an appropriate directory. I chose “~/.local/habits”. Afterwards, I could do this:

$ ls ~/.local/habits
habits  habits.dat  Makefile

If you use bash or zsh you can add the following to the end of “~/.bashrc” or “~/.zshrc”:

# ~/.bashrc or ~/.zshrc

# ... existing content goes here ...

fortune ~/.local/habits

If you’re on fish shell, it’s a bit different. (You should try fish shell, I absolutely love it!) In this case, you need to add the above command to a function called fish_greeting.

# ~/.config/fish/functions/fish_greeting.fish

function fish_greeting
  fortune ~/.local/habits
end

However you configure it, once you’ve made the necessary edits open a new terminal window and you should see a handy reminder!

Bonus points

The code above is pretty useful, but the text doesn’t stand out very much in the console. I found it was a little too easy to ignore it.

There are a few neat tools for the command line that can format text in interesting ways, for example, by drawing ascii-art frames around the text. Two popular ones are cowsay and boxes.

I changed the fortune call so that it pipes the output through boxes. My command looks like this:

fortune ~/.local/habits | boxes -d parchment

… and the end result looks like this:

A screenshot, showing a nice ascii art parchment, with one of my snippets printed in the middle.

Summary

Building my own habit reminder as I’ve described above was something that I’ve found surprisingly useful. I had never really thought of using fortune in this way, but it’s proven to be quick to set up, didn’t require any coding, and it’s helped me to improve how I use the command-line!

If you found this tutorial useful, let me know on Mastodon or Bluesky!