Setting up a nice prompt with iTerm on MacOSX

Recently, I went through a computer replacement. While I appreciate the convenience of Migration Assistant, I prefer to start from scratch as it gives a chance to remove all the unused stuff that I manage to pile up on my disk over time. On the other hand, I lose all the nicely crafted customization in my development environment, and my terminal prompt is one of these things. Since I would jot down a few notes for my future reference, I thought it’d be nice to share my setup, which is based on iTerm + Oh My Zsh + Powerlevel10k and is a slightly tweaked version of Kevin Smets one.

Get iTerm2

If you have homebrew, the easiest way to install iTerm2 is to run:

brew install --cask iterm2

If you don’t have homebrew… install it. Or you can alternatively download iTerm2 from its site and install it.  

Get On My Zsh

Oh My Zsh is an open-source framework for managing your zsh configuration. You can easily install it with curl

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Get Powerlevel10k

Oh My Zsh can use themes, and Powerlevel10k is currently my favorite. The first step for installing it is to clone its git repository:

git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k

Then, you have to edit your ~/.zshrc and set ZSH_THEME= "powerlevel10k/powerlevel10k"

Then, start a new terminal session and the Powerlevel10 configure wizard will be launched to set your prompt. My preferred configuration is: 

Prompt Style: Rainbow.

Character Set: Unicode.

Current Time: 24-hour format.

Separator: Angled.

Prompt Heads: Sharp.

Prompt Tails: Flat.

Prompt Height: 1 line.

Prompt Spacing: Compact.

Icons: Many Icons.

Prompt flow: Concise.

Transient Prompt: Yes.

Prompt Mode: Verbose.

Color settings

I use the color scheme from Solarized Dark theme. To install it, save it as a file somewhere and open it. iTerm2 will import the color settings and you can apply them by selecting Preferences > Profiles > Colors > Load presets

Remove “username@hostname” from prompt

By default, the prompt shows “user@hostname”. 

I don’t like it a lot, especially on my laptop where I’m the one and only user. To remove it, add a line with

DEFAULT_USER=$(whoami)

to your ~/.zshrc.

Get Auto Suggestions

Auto Suggestions is a zsh plugin that shows auto-completion suggestions in your terminal. To install it, clone the repository into $ZSH_CUSTOM/plugin

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

and edit your ~/.zshrc to add zsh-autosuggestions to the list of enabled plugins:

plugins=( 

    # other plugins...

    zsh-autosuggestions

)

Syntax highlighting

I like to have syntax highlighting wherever it’s possible and I found this plugin for zsh

brew install zsh-syntax-highlighting

After installation, edit your ~/.zshrc and add the following to the end:

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

That’s all. 

Please, let me know if you have any interesting tweak or suggestion for a better version of this prompt!