iOS Dev Setup: Customize your terminal

iTerm + zsh + Prezto + Powerlevel9k

This post is part of an ongoing series on setting up an iOS development environment.
iTerm (Chalkboard theme), zsh via Prezto (Powerline9k theme), DejaVu Sans Mono for Powerline Nerd Font Complete

Over time, I’ve tweaked my terminal to provide a good deal of relevant information that’s easy to parse, right when and where I need it. At the end of the day, I have a system where I can easily tell which version control system I’m using, which branch I’m in, and my status (files unstaged, files staged but not commited, etc). I can quickly navigate to to other branches or files using auto-completion and suggestion that’s built into zsh/Prezto. iTerm allows me to open multiple tabs, switch profiles on the fly, and easily update and tweak the look of my terminal. iTerm, zsh, and Prezto do much, much more. Also — it just looks good.

This post will cover how I’ve customized the look and functionality of my terminal. There are infinite combinations, the following is simply the way I’ve currently configured my terminal for iOS development. iTerm2 is my preferred terminal alternative to MacOS’s default Terminal app, which I’ve customized with a color scheme and font that plays well with the zsh theme Powerlevel9k. There are links to my custom zsh dotfiles at the end.

iTerm

Install iTerm and set it as your default terminal application. I strongly encourage you to read over the documentation to get an idea of all that is available.

iTerm theme:

iTerm comes with several built in themes, and a simple Import/Export feature that provides many more. Additional themes can be found with a little Google-fu.

To import a theme new theme:

  • Preview, select and download a new theme. The iTerm-approved themes can be found here: https://github.com/mbadolato/iTerm2-Color-Schemes.
  • Navigate to iTerm preferences, import the downloaded theme, then select. You can see a slightly tweaked version of the Chalkboard theme in the screenshot at the top of the post.
  • If you like, you can adjust a standard or custom theme to fit your needs, then export to share with others.
Note: you will need open a new tab or window in iTerm to view your changes. This holds true for font, color and any other changes you make to the appearance of the terminal.

iTerm fonts:

I’ve gone down a few different paths setting up a font that works well with iTerm and Powerlevel9k. The Powerlevel9k suggested method is to use Awesome Terminal Fonts (detailed tutorial here), which is an elegant but occasionally delicate option. After 3 different MacOS updates broke my font settings, I opted for a simpler solution.

  • Download the patched fonts you want to try from NerdFonts
  • The download may contain extra fonts you don’t need (looking at you, Windows compatible fonts) — go ahead and delete what you aren’t going to install
  • Install the fonts that you want to use. I like DejaVu Sans Mono for Powerline Nerd Font Complete, which you can see in use in the screenshot at the top of the post. If you want to go a step further, organize your new fonts in MacOS’s Font Book application for easier navigation.
  • In iTerm, change the font to your preferred patched Powerline font:

Export and import:

Once you have iTerm set up just the way you like, you can export your profile and save in a safe place for backup or importing to another instance. Navigate to iTerm Preferences --> General --> Preferences --> Load preferences... and browse to your preferred location to import. Use the Save changes to folder... option to export your settings. You must check the Load preferences... box to enable the option to save.

Other:

Another convenient tweak is to set the iTerm tab title to the current directory. Add to your .zprofile file:

# Set iTerm tab title to current directory
precmd() {
echo -ne "\e]1;${PWD##*/}\a"
}

Note: This can also be done in your .zpreztorc file, if you prefer.

zsh + Prezto + Powerlevel9k

zsh

The simplest way to install the lastest version of zsh is to use Homebrew. If you don’t yet have Homebrew installed, please see this previous post. In your terminal, enter the following:

brew install zsh

To set zsh as your default shell, enter the following:

sudo -s 'echo /usr/local/bin/zsh >> /etc/shells' && chsh -s /usr/local/bin/zsh

Prezto

Once you have zsh, you can install Prezto. While packages like Oh-My-Zsh are more popular, I find Prezto to be a more streamlined — but still robust — option.

Install Prezto following the instructions on the README.md. There are a lot of Prezto settings you can play around with by editing the .zpreztorc file — take a look at the options that streamline your flow like auto-completion and correction.

Powerlevel9k

Ok, now we’re getting to the fun stuff. The Powerlevel9k repo can be found here. There is a ton of documentation, and you could seriously overload on the sheer volume, so lets take this one step at a time.

  1. Install the theme for Prezto. See line 96 in .zpreztorc below for where you should specify the correct theme for Prezto.
  2. Set up the theme to use the font you installed in previous steps. See lines 2–9 in .zshrsc below to see where to specify the font configuration. Please note that the font needs to be declared before Prezto is sourced to work correctly.
  3. THE PROMPT. The prompt is the exciting part:) This is also where the iTerm theme you selected in previous steps will really shine.

Below I’ve added my current .zshsrc.zpreztorc, and .zprofile files. Please see the screenshot above to see what it looks like with Powerline icons, color changes for git status, git branch, 2 line prompt, and more.

I’d like to thank Ustice for introducing me to Powerlevel9k in a talk he presented several months ago.

.zshsrc:

.zpreztorc

.zprofile