
Background information
Linux can give your old Mac a new lease of life
by Kevin Hofer
With macOS, the terminal’s not just a tool, but a playground too. Cowsay lets you turn cows, dragons and the like into talking ASCII stars. It’s colourful, pointless but fun.
The terminal in macOS is particularly useful for automated processes on your Mac or for running network and diagnostic tools. One particularly useful tool is Homebrew, a package manager for macOS. It carries out roughly the same function in the terminal for your Mac as the App Store for iOS on your iPhone: installing, managing, updating or deleting programs – a kind of toolbox for everything that Apple doesn’t provide itself.
But things don’t need to be all dull and serious. In fact, it features a few silly but funny gimmicks and Easter eggs. For example, there’s command line tool Cowsay, a nod to Unix/Linux, which is what I’ve dedicated this article to.
Basically, Cowsay simply displays certain forms in ASCII code. The community is continuously expanding this small ASCII decoration tool. These days, it features dozens of shapes and animals that are happy to present a text of your choice in a speech or thought bubble – even in colour or as a start banner if you want.
In the late 90s, programmer Tony Monroe wrote Cowsay as a Perl script for Unix/Linux. It spread rapidly in the various distros and soon became a cult-status Easter egg: together with Fortune – another program that generates random quotes – it’s been used for countless presentations or login banners. Thanks to the Homebrew tool, Cowsay is still available, even for macOS. And since it’s so wonderfully unnecessary, it’s timeless.
To install Homebrew, proceed as follows: press the Command+Space key to make the search window appear. Enter Terminal and press Enter. Enter a password for the installation. It’s the same password you use to log in to your Mac.
Once that’s done, the terminal appears. Enter the following command in the terminal and press Enter:
/bin/bash -c "$(curl -fssL https://raw.githubusercontent.com/«Homebrew»/install/HEAD/install.sh)"
You’ll be asked for the password you use to log in to your Mac. Enter this password. Then set up the path for Homebrew so that the terminal can find the command at any time. To do this, enter the following command in the terminal:
If your Mac has an M processor:
echo 'eval "$(/opt/«Homebrew»/bin/brew shellenv)"' >> ~/.zprofile eval "$(/opt/«Homebrew»/bin/brew shellenv)"
If your Mac has an Intel processor:
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile eval "$(/usr/local/bin/brew shellenv)"
To try out all the features and design options, it’s best to install all four packages: Cowsay, which displays all the animals in ASCII code, Cowthink, which can add a thought bubble to the animals, Fortune, which generates random quotes and sayings, and Lolcat, which makes everything colourful. You do this by typing in these four command lines one after the other and pressing Enter in each case.
brew install cowsay brew install cowthink brew install fortune brew install lolcat
What you need now is the package called shuf. It’s a basic tool for the Unix/Linux command line, which outputs content and lines in random order, but isn’t installed by default on macOS. You need this package for the random sayings and animal of the day. So you need to install that too:
brew install coreutils
To avoid reinstalling it every time, you need to tell the directory to save these «coreutils». Here’s how:
echo 'alias shuf="gshuf"' >> ~/.zshrc && source ~/.zshrc
Then press Enter again.
Now the fun begins. I’ll give you an example of how to use each of these packages and how you can combine them.
Let’s cover the simplest stuff first. Making the cow speak or think. To do this, enter the following command line in the terminal:
cowsay "Hello! I’m a cow"
or
cowthink "I think I’m a cow"
If you get bored with the cow, there are other things to choose from. Instead of providing you with a long list of them, Cowsay does this. Enter the following command in the terminal:
cowsay -l
If you want to change animals, enter this:
cowsay –f ANIMAL NAME "Your example sentence"
If you want the whole thing to be colourful instead of the typical black and white of the terminal, you can activate all colours. Here’s an example:
echo "Your example sentence." | cowsay | lolcat
You don’t always have to come up with your own quotes. That’s what you installed Fortune for. Get your random animal saying something random as follows:
fortune | cowsay -f $(cowsay -l | tail -n +2 | tr ' ' '\n' | shuf -n 1) | lolcat
If you want a random animal to greet you on starting the terminal, the command you need is:
"echo 'fortune | cowsay -f $(cowsay -l | tail -n +2 | tr " " "\n" | shuf -n 1) | lolcat' >> ~/.zshrc"
The bold part of the code ensures that the script can remember something’s installed or something’s part of a routine that’s loaded each time. Such as your desired random animal.
Further exciting packages that make Homebrew easier or simply more fun will follow in another part of the macOS tip series.
I've been tinkering with digital networks ever since I found out how to activate both telephone channels on the ISDN card for greater bandwidth. As for the analogue variety, I've been doing that since I learned to talk. Though Winterthur is my adoptive home city, my heart still bleeds red and blue.