iTerm2 with Oh My Zsh on Macbook

Preface

This post is a backup referrence for me. It talks about iTerm2 with Oh My Zsh and its various plugins to build an awesome terminal.

Prerequisite

  • git
  • homebrew

iTerm2

Download iTerm2.

After installation, a zsh file should appear under /bin directory. To use zsh shell:

1
chsh -s /bin/zsh

To change back to the default bash shell (But trust me, you don’t want to do it after using zsh with Oh My Zsh):

1
chsh -s /bin/bash

Oh My Zsh

Install Oh My Zsh.

Powerline

Powerline Homepage

1
pip install powerline-status --user

Powerline Fonts

1
2
3
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh

After installing Powerline Fonts, go to iTerm2 -> Preferences -> Profiles -> Text and look for Font to change it. I used Meslo LG L for Powerline L size font.

change_iTerm2_Font

Solarized Color

1
2
3
git clone https://github.com/altercation/solarized
cd solarized/iterm2-colors-solarized/
open .

This opens finder window, by double clicking Solarized Dark.itermcolors or Solarized Light.itermcolors file to install the color. Then go to iTerm2 -> Preferences -> Profiles -> Colors -> Colors Presets to choose you preferred color.

Theme

1
2
3
git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
cd oh-my-zsh-agnoster-fcamblor/
./install

The above command installs agnoster theme to Oh My Zsh themes. Look for ZSH_THEME in ~/.zshrc to make the theme changes:

$HOME/.zshrc
1
2
- ZSH_THEME="robbyrussell"
+ ZSH_THEME="agnoster"

After that, either relaunch iTerm2 or with source ~/.zshrc command to apply the latest zsh configuration.

Configurations

Natual Text Selection

By default, word jumps (option + or ) and word deletions (option + backspace) do not work. To enable them, go to iTerm -> Preferences -> Profiles -> Keys -> Key Mappings, look for Presets... and change to Natural Text Editing.

change_iTerm2_Natual_Text_Selection

Custom Prompt

By default, your terminal will now show “user@hostname” in the prompt, which might be too long. To remove this, you can add the line DEFAULT_USER=$(whoami) to ~/.zshrc.

Maximize iTerm2

Personally, I prefer to use a shell in the maximized window. Go to iTerm -> Preferences -> Profiles -> Window, look for the Style section and change to Maximized option.

Plugins

There are many many plugins available for Oh My Zsh. For me, I use the following plugins:

$HOME/.zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
autojump
k
copydir
copyfile
copybuffer
jsontools
macos
web-search
)

Below are the web pages I have referred to when researching the top popular plugins:

  1. Top 10 Oh My Zsh Plugins For Productive Developers - Travis Media (The timestamp I used for this YouTube video shows all the plugins introduced in the video)
  2. Top popular Zsh plugins on GitHub - Krystian Safjan’s Blog

For adding plugins, you could try to add them in the ~/.zshrc configuration file and apply the settings by source ~/.zshrc. Some plugins are already installed by Oh My Zsh, those plugins are not installed will be prompted. You can install them accordingly. Installation guides for some plugins:

zsh-autosuggestions

For this plugin, the color for the auto suggested command lines might be too close to the background. To change auto suggested command color, go to iTerm -> Preferences -> Profiles -> Colors -> ANSI Colors, the first one in the Bright column is the auto suggested command color setting. For me, I used 80% Gray.

iTerm2_change_auto_suggested_command_color

VS Code Issue

For the embedded terminal in VS Code, it might not properly represent the powerline prompt. To fix it, go to Code -> Preferences -> Settings, toggle to the JSON configuration file and change:

settings.json
1
2
3
4
5
6
7
{
...
// zsh terminal and font fix for vscode
+ "terminal.integrated.defaultProfile.osx": "zsh",
+ "terminal.integrated.fontFamily": "Menlo for Powerline",
...
}

Note: It is recommended to use the User level here, as we would like to apply these settings to the entire VS Code editor, not only a single project

Referrence

Using Alt/Cmd + Right/Left Arrow in iTerm

iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

iTerm2 + Oh My Zsh (In Chinese)

Fix powerline in VS Code