Published at
Updated at
Reading time
6min

I'm jumping back and forth between iTerm2 and Hyper for quite a while now. Hyper is beautiful, JavaScript-extensible and provides a very clean and reduced look.

Unfortunately, it felt always a few milliseconds slower and less responsive than iTerm to me. This tiny difference led me to come back iTerm2 even though I found Hyper visually more appealing.

With the release of v3.3 of iTerm2 (I only just recently noticed this version mixup โ€“ v3 of v2 ๐Ÿ™ˆ) a Minimal and Compact theme entered the stage. That motivated me to prettify my iTerm2/ZSH terminal.

Today, I'm very pleased with my setup, and people asked me to share my settings โ€“ so here we are!

My terminal setup including command syntax highlighting, random emojis on every prompt line, command suggestions, reduced iTerm2 and a custom status bar

Before we start: I use the latest iTerm2, zsh, and oh-my-zsh. Most but not all of the described things work in a different environment.

New iTerm2 themes โ€“ Compact and Minimal

You can find the new theme selection under Settings > Appearance.

Appearance dialog in iTerm2

The themes differ in the top and bottom bar. ๐Ÿ‘‡

Different iTerm2 themes next to each other โ€“ regular, compact and minimal

If you looked closely, you probably noticed that you can also configure the position of the status bar, which comes next, in this dialog. I prefer it to be at the terminal bottom.

The new custom iTerm2 status bar

You can set the elements inside the status bar under Profiles > Session and find it a "Configure Status Bar" button in the bottom.

Profiles - Session dialog in iTerm2 settings

The new status bar provides a bunch of elements to display battery status, git status, and other useful things.

Status bar settings in iTerm2

Unfortunately, there is no element showing the current Node.js version (yet). Additionally, the Current Directory element shortens the file path when you use Prefer tight packing to stable positioning (it moves all the items to the left), which you'll find under the advanced settings.

To solve these issues, you can use the Interpolated String element which enables you to display whatever you want right in the status bar.

Custom variables in the status bar

To set custom iTerm accessible variables, have a look at this tutorial. You have to enable the shell integration and to define a iterm2_print_user_vars function.

# .zshrc
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"

iterm2_print_user_vars() {
  # extend this to add whatever
  # you want to have printed out in the status bar
  iterm2_set_user_var nodeVersion $(node -v)
  iterm2_set_user_var pwd $(pwd)
}

For me, these are defined in my .zshrc. You see above that I define pwd and nodeVersion, which then are available in the Interpolated String element under user.

Settings for the Interpolated String element in the iTerm2 status bar

Other iTerm2 settings

These are my primary iTerm settings. Let me share some other minor things...

The color theme

I use Sindre Sorhus' Snazzy color theme.

Color theme setting in iTerm2 showing the Snazzy theme

More space inside of the terminal window

And I like it to have a little bit of padding in my terminal which you can define in the advanced iTerm settings when you search for margin.

Advanced iTerm2 settings showing the margin options

Command syntax highlighting and auto-completion preview

As I'm using oh-my-zsh, the command highlighting and suggestions come out of the box. oh-my-zsh provides a bunch of useful plugins.

These are the ones I use:

# .zshrc
plugins=(git node npm github zsh-syntax-highlighting zsh-autosuggestions git-open)

iTerm2 showing command highlighting and command suggestions

zsh-syntax-highlighting and zsh-autosuggestions are the plugins highlighting the current command inline and also showing suggestions from the command history. Have a look at the plugins listing; there is more good stuff in there.

My custom theme

The theme doesn't include much fanciness except the emojis. I copied the idea from Mathias Buus who showed his terminal in a talk years ago, and he was so kind to give me an initial implementation.

Overall, it's a collection of emojis that are accessed with a random number inside of the terminal prompt. In case you ran into a problem with emojis in the past... iTerm doesn't render all available emojis with the same width. Yes, I went through all of them one by one to not have a jumping terminal prompt.

This led to 665 different emojis rendered in my terminal prompt.

# stefan-judis.theme
PS1_EMOJIS=("๐Ÿ˜€" "๐Ÿ˜ƒ" "๐Ÿ˜„" "๐Ÿ˜" "๐Ÿ˜†" "๐Ÿ˜…" "๐Ÿคฃ" ...)
NUMBER_OF_EMOJIS=${#PS1_EMOJIS[@]}
THEME_DELIMITER="%{$fg_bold[blue]%}โ€บ%{$reset_color%}%{$fg_bold[red]%}โ€บ%{$reset_color%}%{$fg_bold[green]%}โ€บ%{$reset_color%}"

PROMPT='
%(?, ,%{$fg[red]%}FAIL: $?
%{$reset_color%})
${PS1_EMOJIS[$RANDOM % $NUMBER_OF_EMOJIS]}  $THEME_DELIMITER '

RPROMPT='%{$fg_bold[blue]%}[%*]%{$reset_color%}'

You can change the delimiter with the THEME_DELIMITER variable. Currently, it's three colored arrows.

Because I'm using oh-my-zsh the theme also includes provided color handling (e.g. $fg_bold) and functionality like the current time with %*.

I use PROMPT to show the emojis and RPROMPT to display the current time on the right side.

iTerm with a new random emoji on every prompt line

The emoji part should work just fine in any shell environment. If you want to have a look at the theme on GitHub, here we go.

In case you have weird blue triangles in your terminal after copying the theme have a look at this GitHub issue.

Commands I use daily and people usually ask about

A colorful list command

To have a look at files in a directory, I use exa, which makes the output more beautiful and also has a bunch more settings than the default ls. I have it aliased to ll.

Very colorful output of exa aliased to ll

I'm rarely navigating somewhere with the whole path. And while many tools let you go somewhere quickly, I stuck on autojump which is aliased to j.

# navigate to /Users/stefan/projects/.dotfiles
# using autojump from anywhere
$ j dotfile

A quicker clone

When I clone repositories from GitHub, I use a custom clone function. It automatically clones a repository, navigates into it, and performs npm install if there is a package.json available.

# Usage:
# $ clone git@github.com:random-mdn/random-mdn-serverless.git
clone() {
  git clone $1
  cd $(basename ${1%.*})
  if test -f "./package.json"; then
    echo "..."
    echo "Found package.json... installing dependencies"
    echo "..."
    npm install
  fi
}

A better cat

The usually available cat command is aliased to bat which is "a cat clone with wings", and it's so good. It automatically does syntax highlighting and shows git modifications. I love it!

Colorful output of bat showing also git status

And that's it friends!

Feel free to snoop around in my dotfiles for more things. The repository doesn't include a proper Readme, but usually, there are comments next to the commands and definitions.

Have a wonderful day!

If you enjoyed this article...

Join 5.5k readers and learn something new every week with Web Weekly.

Web Weekly โ€” Your friendly Web Dev newsletter
Reply to this post and share your thoughts via good old email.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles