Customizing the Terminal on macOS

In this post I’m going to show you how you can vastly improve your terminal. We’ll start with the default terminal shown in the first screenshot and enhance it so that it looks something like the terminal shown in the second screenshot:

Terminal before customization Terminal after customization

We’ll accomplish that by switching the shell from the default shell Bash to the much more powerful and customizable Z shell. On top of that we’re going to add the configuration framework Oh-My-Zsh in order to simplify the configuration process. Then we will replace Apple’s stock terminal emulator with the more powerful iTerm 2 and change the terminal’s appearance with a nice color scheme.

Installing the Z Shell

Like many other system programs, zsh is already installed on your Mac by default. You can verify that by entering which zsh into your Terminal. As with most other pre-installed software, however, this system-provided version of zsh is pretty outdated and shouldn’t be used. We’re going to install our own version of zsh instead, using a tool called Homebrew. This version will be easier to maintain and works much better with the rest of your software. Thus you should know how to use Homebrew before you continue reading. If you don’t know what Homebrew is, I covered it in-depth in a previous blog post. Go read that post first and come back here afterward.

Once you’ve installed Homebrew, you can install the most recent version of zsh with this command:

brew install zsh

Next we’re going to install Oh-My-Zsh, a great framework for zsh which really simplifies its configuration and includes a couple of cool themes for the prompt.

sh -c "$(curl -fsSL"

Before you can actually start using this newly installed version of zsh, you first need to add it to the list of known shells, which is located at /etc/shells. Sounds complicated, but is really simple. All you need to do is to run this command:

echo "/usr/local/bin/zsh" | sudo tee -a /etc/shells

With this command we’ve only made the new shell available to the system. To actually use the new shell, we also need to explicitly tell the system to.

chsh -s /usr/local/bin/zsh

Checking the title bar of confirms that you’re now using zsh instead of bash. You might have to close the terminal and re-open it for the changes to take effect. So now that we’ve successfully made the switch to zsh, this next step might seem superfluous at first—we’re going install a current version of bash, too. The reason is that during the execution of some commands such as brew update you will see the job name in the title bar of the terminal window changing from zsh to bash. So just because you aren’t using bash anymore does not mean that it isn’t used by various background processes anymore. Thus keeping bash up-to-date, too, seems like a good idea. Like zsh, the pre-installed version of bash is pretty outdated, so we should install our own version of bash for the same reasons as above:

brew install bash

While we’re at it anyway, we can add that new version to /etc/shells, too, just in case you want to go back to bash some day. Since we don’t run the command for actually changing the shell afterward, adding it to /etc/shells has no effects at all.

echo "/usr/local/bin/bash" | sudo tee -a /etc/shells

Installing Plugins

Next, let’s install a few of the plugins that make zsh so much better than bash. The first one is syntax highlighting.

brew install zsh-syntax-highlighting
echo 'source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> ~/.zshrc

The next plugin is simply called “z” and remembers the paths you cd into. You then only need to type the first couple of letters of a folder instead of its entire path, for example z proj instead of cd ~/some/pretty/long/path/to/project-folder. This is a huge timesaver.

brew install z
echo '. `brew --prefix`/etc/profile.d/' >> ~/.zshrc

Another cool plugin is auto suggestions. It tries to complete the missing words to your command before you’ve even started typing them, very much like what a Google search in your web browser does:

brew install zsh-autosuggestions
echo 'source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh' >> ~/.zshrc

For those plugins to work, we had to add a line of code to a certain file located at ~/.zshrc. This file contains all the run commands for zsh.1 For bash there are similar files, such as ~/.bashrc and ~/.bash_profile. These kind of files are called dotfiles. If you’re interested in what they are and how they work, you can read more about them here.

What you need to know about dotfiles for now is that a few important things are probably going to break after switching from bash to zsh. That is because you’ve most likely set your environment variables (e.g. PATH, JAVA_HOME etc.) in either ~/.bash_profile, ~/.profile or ~/.bashrc. These three files are all meant for bash and will not be read by zsh.2 Therefore your system won’t know your PATH or JAVA_HOME anymore—it’s like you had never told the system about them in the first place. This is why you should really read the post about dotfiles mentioned above to understand this important topic better. Otherwise things might just not work anymore and you’d have absolutely no idea why.

To make things work again, you need to tell zsh the values of these variables in a language zsh is able to understand, figuratively speaking. One way to do that is by simply sourcing your respective dotfile from ~/.zprofile. If you’ve followed my guide, it would be ~/.profile which you need to source:

echo "[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'" >> ~/.zprofile

This command tests whether ~/.profile exists and if so, emulates the sh shell in order to source ~/.profile. The reason for this is that the syntax of zsh is not completely compatible with sh and bash. These incompatibilities could potentially break scripts such as ~/.profile or ~/.bash_profile if we don’t enter emulation mode before reading these files when using zsh.

Customizing the Appearance of the Terminal

If you’re like me, you really don’t care about that very first line in the terminal which tells you the time of your last login. You can suppress it like so:

touch ~/.hushlogin

Next, you’ll want to alter the prompt of your terminal. First, visit the themes website and check out which themes you like. Personally, I like nebirhos the most. After you’ve found a favorite, open ~/.zshrc in a text editor, for example with this command:

open -e ~/.zshrc

In this file, search for the line ZSH_THEME="robbyrussell" and replace robbyrussell with the name of the theme you want to try. For the change to take effect, you either need to open a new terminal window or execute source ~/.zshrc. This is one of the many great simplifications made possible by Oh-My-Zsh.

I made some additional tweaks to nebirhos and adjusted it to my liking, since I don’t need to see my user name or the name of my computer next to the arrow all the time. To modify a theme, you can either open its folder with

open ~/.oh-my-zsh/themes/

and search for the theme in the Finder, or alternatively open the theme directly if you know its name:

open -e ~/.oh-my-zsh/themes/nebirhos.zsh-theme

Beware that these “themes”—despite their name—modify only the appearance of the prompt, e.g. the fat arrow at the beginning of each line, but not the background color of the terminal etc. To change the background color, a color scheme is what you’re looking for.

As you can see, you can use zsh with, too; none of the changes so far had to do anything with iTerm. But I recommend using it instead of Apple’s, nevertheless, since its far more customizable. You can install it with this command:

brew cask install iterm2

Color Schemes

You can find many pretty color schemes for iTerm here. My favorites are Dracula and Urple. You can either download the whole folder as a zip-file or take the shortcut and download the mentioned schemes directly via curl to your Downloads folder.

cd ~/Downloads
curl -O
curl -O

Then go to Profile > Colors in iTerm, where you can import the color schemes.

General Settings

I dislike the native full screen when you press +Enter, so I deactivated it under General > Window. Under Profile > Terminal you should enable “Silence Bell” to disable the annoying sound effect. Change the font to a prettier one by first installing Source Code Pro as follows and then setting the font and font size under Profile > Text. I’ve set it to 13pt Source Code Pro.

brew tap caskroom/fonts
brew cask install font-source-code-pro

Keyboard Shortcuts

Add two new key mappings under Profiles > Keys for quicker navigation between words by click the + button you will find there.

Word Jump to the Left

To create a keyboard shortcut that will move the cursor to the left by one word, click in the field named “Keyboard Shortcut” and press the key and the left arrow key simultaneously, so that the combination ⌥← appears. Select Send Escape Sequence as action and enter the letter b in the Esc+ field where it says “characters to send”. Confirm with “OK”.

So to recap, here’s what you should do:

Keyboard Shortcut:	⌥←
Action:			Send Escape Sequence
Esc+:			b
Word Jump to the Right

Same procedure as above, except that you press the right arrow key and enter the letter f instead of left arrow and b .

Keyboard Shortcut:	⌥→
Action:			Send Escape Sequence
Esc+:			f

Final Words

You might want to explore the other settings to adjust iTerm even further to your needs. For example, you might want to assign a system-wide hotkey to open the terminal from anywhere. Since this comes down to personal preference, from here on I’ll leave you to figure out for yourself which settings you find useful.

If this article was helpful, why don’t you let me know and leave a comment down below? This keeps me motivated to write even more guides for you :blush: Also, I’d really like to see what you’re doing out of your terminal. Hit me up on Twitter if you want to share a screenshot of your masterpiece or in case you found a helpful little plugin I didn’t mention.

  1. “rc” derives from “runcom”, from the MIT CTSS system, ca. 1965. (Source

  2. zsh is not compatible with traditional sh syntax which is the predecessor of bash