How I customise my Terminal with Oh My Zsh (macOS)
Tags: tooling, beginners, tutorial, terminal
Published: 2021-04-30 13:53:33

As a software engineer I use the command line every day. It's very important to me that the tool I stare at for hours looks nice and that I have a set up that saves me time and energy. I use the macOS default Terminal because that's what I used when I started learning to code and I'm loath to change (soz). The macOS Terminal is a ZSH terminal shell (aka Z shell) which runs on a Unix-like operating system (macOS, Linux, BSD, Windows/WSL2). This post will go through how I set mine up on my personal MacBook Air (2015) running Big Sur, your experience on a different operating system may differ but luckily Oh My Zsh is a very popular framework so there will probably be people on Stack Overflow/Reddit who have encountered the same issues! 

## Step 1: Downloading Oh My Zsh

Oh My Zsh is opensource framework for terminal configuration that has loads of themes and plugins.

You can download Oh My Zsh from their [website](https://ohmyz.sh/) via `curl` or `wget` by copying and pasting the command. Make sure you're in your system's root folder.

## Step 2: Configuring the `.zshrc` file

The `.zshrc` file contains the script that is run when you start a new zsh shell (`rc` stands for "run commands"). So if you make changes to this file you have to start a new shell to see them take effect.

You can customise your terminal by running `open ~/.zshrc` to open the `.zshrc` file in your system's root folder (the `~` tilde symbol means home directory).

Note: if you're on macOS Catalina or above you may get the error `zsh: permission denied:` - you will need to configure permissions to open the file with `chmod +x ~/.zshrc`.

## Step 3: Changing the Terminal theme

Choose your theme from the [Oh My Zsh Themes](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes) and change the `ZSH_THEME=""` line in the `.zshrc` file.

I use the [agnoster](https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster) theme so I have `ZSH_THEME="agnoster"` in my `.zshrc` file.

![](https://i.imgur.com/91TaP8h.png)

When you run a new shell you should see it has a new theme - yay! But wait...what are all those questions marks? You need to download the fonts to see the cool symbols!

## Step 4: Installing Powerline Fonts

Follow the instructions on the [Powerline fonts README](https://github.com/powerline/fonts) to download the fonts needed for your new theme.

## Step 5: Changing your Terminal Fonts

Go to `Preferences > Profiles > Font` to change the font for your Terminal to any of the fonts that have Powerline in the name. I use `Meslo LG L DZ Regular for Powerline`. You can either change the Basic profile or make a new profile and make that your default profile.

![](https://i.imgur.com/rSqt4if.png)

Now the question marks should be replaced with cool symbols. The purple arrow indicates what directory you are in, and the green arrow indicates what branch you are on if you are in a git initiliased directory.

## Step 6: Changing your colours

You can play around with the colours in the Terminal Profiles yourself but I would suggest going with a pre-made theme because they will have considered the constrast and readability of the colours in different scenarios. Here's a list of cool [MacOS Terminal Themes](https://github.com/lysyi3m/macos-terminal-themes).

I use the [VS Code Dark Plus](https://github.com/lysyi3m/macos-terminal-themes#vs-code-dark-plus-download) theme which looks like this:

![](https://i.imgur.com/IOOGIcb.png)

You can download the `.terminal` file and go to your Terminal `Preferences > Profiles` and import it as a new profile. Then select `Default` to make it your default theme.

![](https://i.imgur.com/APP9LSs.png)

Now it looks beautiful! :lipstick: :nail_care: 


## Plugins

There's so many other things you can do with Oh My Zsh. Have a look at the [plugins](https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins) it comes bundled with. I use the aliases that come with the [Git plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git) every day. An alias is a shortcut for a command that you write instead of the command and it runs the command.

The Git aliases I use the most are:

| Alias | Git Command |
| -------- | -------- |
| ggp |	git push origin $(current_branch)|
|gcb <new-branch-name>|	git checkout -b <new-branch-name>|
|gco <branch-name> | git checkout <branch-name> |


## Aliases

You can add your own custom aliases by adding them to your `.zshrc` file

The bottom of the file has the syntax for aliases in comments:
```
# Example aliases
# alias zshconfig="mate ~/.zshrc"
```

I have the command for editing my `.zshrc` file under the alias `edit`. I prefer editing the file in VS Code* so I have this in my file:
`alias edit="code ~/.zshrc"`

###### *The instructions to set up launching files in VS Code from the command line can be found [here](https://code.visualstudio.com/docs/setup/mac) for macOS.

## :art: That's all! :tada: 

Customising the Terminal is a great place to start personalising your tooling, apparently you can do even cooler things with iTerm2 and you can customise that in much the same way as I've outlined in this tutorial.