Texts | Christofer Sandin

01001100 00101101

Terminal: The Konami code for your terminal

To make the terminal on macOS a bit nicer, I thought we could use the famous Konami Code to give our friend some extra functions that improve everyday life.

These are entirely subjective opinions from someone who uses the terminal more often now than before. Many things are incredibly faster to do there compared to doing the same thing in other programs and interfaces, so once you get used to it, it’s hard to stop.

It’s also time for me to change computers, and I thought it would be nice to have a little guide to follow since I always start every new computer with a completely fresh installation. It becomes a bit of a fresh start and is a strategy that has worked well for me for nearly twenty years.

However, in addition to mentally pressing the classic code ⬆️ ⬆️ ⬇️ ⬇️ ⬅️ ➡️ ⬅️ ➡️ 🅱️ 🅰️, you need to take a couple more steps.

Stay tuned!


⬆️ ⬆️ – Install the basics

I consider a few things essential, and if you’re going to work with some form of development on a Mac, these are probably some of the first things you need to install to have a functioning environment.

Install Xcode and then CLI Tools for Xcode

You can certainly do this via the App Store, but isn’t it convenient to do it through the terminal instead?

xcode-select --install

Install Node.js and npm

Start by following the instructions at  https://nodejs.org/en/ .

Then, there’s one more thing that should be done for a smooth everyday experience, which is to make sure that all global packages are installed in your home directory instead of the system directory that is the default.
We do this to avoid permission issues and having to type sudo before all npm installations for all eternity…

mkdir ~/.npm-global 
npm config set prefix '~/.npm-global'

We also need to add the path in .zshrc so that we can use the packages from anywhere:

# Node.js global folder in ~/.npm-global
export PATH=~/.npm-global/bin:$PATH

Homebrew

Homebrew is a package manager for MacOS. Let’s install it and then use that to install the other packages.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install iTerm2

I use iTerm2 instead of the built-in terminal. Several little things are quite a lot nicer, and I’ve gotten used to it. There are other options today, and I’m currently testing both Ghosty and WezTerm, but ”if it ain’t broke, don’t fix it” works for me in this case.

brew install --cask iterm2

To make adjustments, you modify the file .zshrc:

vim ~/.zshrc

⬇️ ⬇️ – Install "Oh My Zsh"

Nowadays, MacOS comes with Zsh as the shell instead of Bash.

I have been using Zsh for many years, so this is something I appreciate, but to make Zsh even better, an easy win is to install Oh My Zsh:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Plugins

I use a few external plugins that need to be installed and some that come included but need to be activated in .zshrc.

With the two installed above, my .zshrc looks like this:

plugins=(git npm extract k)
source $ZSH/oh-my-zsh.sh
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

Themes

There are also a number of different themes, and right now, I’m using af-magic, which I’m pretty happy with.

⬅️ – Fonts with superpowers

To get a bit more out of the terminal, you can install some Nerd Fonts. Here, we install it together with the Hack typeface.

brew tap homebrew/cask-fonts
brew install --cask font-hack-nerd-font

➡️ – Nicer colors

To improve the colors in the terminal, I like vivid, which I came across recently. We use Homebrew again to install:

brew install vivid

One little "gotcha" is that you also need to install the GNU version of ls instead of the BSD version included with MacOS to be able to use the colors:

brew install coreutils

Then you can set the colors you want to use along with a little alias in .zshrc to make everything look tidy:

# Vivid colors
export LS\_COLORS="$(vivid generate molokai)"
alias ls="gls --color"

Here with the molokai colors.

⬅️ – More superpowers

I probably use about a dozen commands in the terminal most of the time, but there are a few commands that I benefit from every day, and the most used is z, which this list starts with. The others are good, too, but they’re used much less frequently.

z

If there’s one command you should install, it’s z. With z, you can jump around among the directories you use the most using fuzzy shortcuts.

brew install z

Add to .zshrc:

# z
. $(brew --prefix)/etc/profile.d/z.sh

This means you can simply type z site instead of cd \~/Sites, for a simple example. It is invaluable if you work a bit more in the terminal.

lsd

With Nerd Fonts in place, we can also install LSD, which stands for LSDeluxe and nothing else, using Homebrew:

brew install lsd

I’m not the biggest fan, but it might suit you.

htop / btop

It’s not something I use daily, but htop is an updated version of top that shows active processes and memory usage in the terminal. It can be installed with:

brew install htop

Or, if you rather, go with the even better looking one called btop

brew install btop

tldr

You can use man to get help with syntax and other things, but these summaries are often very long and quite complicated to read. To make things easier, you can use tldr, which stands for "too long, didn’t read", by installing it with npm:

npm install -g tldr

This means we can now run tldr ln instead:

 ln

  Creates links to files and directories.
  More information: https://www.gnu.org/software/coreutils/ln.

  - Create a symbolic link to a file or directory:
	ln -s /path/to/file\_or\_directory path/to/symlink

  - Overwrite an existing symbolic link to point to a different file:
	ln -sf /path/to/new\_file path/to/symlink

  - Create a hard link to a file:
	ln /path/to/file path/to/hardlink

Compare that to man ls if you can handle it…

trash

Sometimes, it’s nice for files that you delete to go to the trash first.

In the terminal, rm deletes files permanently right away. Not great if it’s a mistake… Add the command trash to send files to the trash instead.

brew install trash

neofetch

Then everyone benefits from a bit of nice ASCII graphics in their terminal, so remember to install neofetch with:

brew install neofetch

➡️ – Restart after changes

Every time you make a change in .zshrc, you need to restart the session for the change to take effect.

You can, of course, just close iTerm and start it again, but it’s easier to do exec zsh.

🅱️ 🅰️ – In summary

Now, finish by pressing 🅱️ and then 🅰️ to complete the Konami code, and the terminal will be significantly nicer the next time you sit down at the computer to get something done.

Epic win! ✌🏻