Gert Lombard's Blog     About     Archive     Feed
My passion is code quality, automated testing, software craftsmanship.

Prettier OSX terminal with iTerm2 and Prezto

I wanted to describe my current Mac OS X shell setup. I’ve switched from the default to iTerm2. This includes the following:

  • switched from bash to zsh
  • use prezto framework for a prettier colorful prompt
  • set up a few iTerm2 triggers e.g. to capture and highlight or show Android gradle build errors etc.

I’ll list every step I took to install all the various pieces:

1. preparation

First install Homebrew if you don’t have it yet:

ruby -e "$(curl -fsSL"

And we also need caskroom to install apps with binary installers:

$ brew install askroom/cask/brew-cask

2. install zsh

$ brew install zsh

3. install iTerm2

$ brew cask install iterm2

4. configure zsh as the new default shell

Just for interest’s sake, this is to show that originally I was on bash:

$ echo $SHELL

Now change my default shell to zsh:

$ chsh -s /bin/zsh

Re-open iterm2 and check the shell version again to confirm zsh is running:

% echo $SHELL

Specify custom location for my dot-files so I can save them in a git repository at BitBucket:

% mkdir ~/dotfiles
% cat <<EOT > ~/dotfiles/.zshenv
export ZDOTDIR=~/dotfiles
source "\${ZDOTDIR}/.zprofile"
% touch ~/dotfiles/.zshrc # will put my fav aliases and functions here
% ln -s ~/dotfiles/.zshenv ~/.zshenv

Quick example of some handy aliases etc in .zshrc:

% export ZDOTDIR=~/dotfiles
% cat <<EOT >> ~/dotfiles/.zshrc
source "\${ZDOTDIR:-\$HOME}/.zprezto/init.zsh"
export JAVA_HOME="`/usr/libexec/java_home -v '1.7*'`"
alias ll='ls -FGlAhp'
alias gca='git commit -a --amend'
alias gr='./gradlew'
# etc...

5. get prezto

% git clone --recursive "${ZDOTDIR:-$HOME}/.zprezto"

Symlink some default prezto config files:

for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^; do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"

Re-open the iterm2 window to see if all the dotfiles are set up correctly (i.e. zprezto modules are loading without errors).

Set the theme (I use steeef built-in theme), modules (like git) etc in .zpreztorc:

% vi $ZDOTDIR/.zpreztorc

For example, to change the theme in .zpreztorc from the default, look for the following line and change sorin to steeef:

zstyle ':prezto:module:prompt' theme 'sorin' # <-- change 'sorin' to 'steeef'...

After setting up vi key bindings, ^R for history substring search stopped working. View the current key bindings - this confirms ^R is currently bound to redisplay instead of history-incremental-search-backward:

% bindkey -L | grep '\^R'
bindkey "^R" redisplay

I added this line to my ~/dotfiles/.zshrc file to enable ^R history search again:

bindkey "^R" history-incremental-search-backward

This setup was inspired by this post by Mike Buss.