Shell 🐚 like a pro with iTerm and oh-my-zsh

If you are looking to revamp your Mac terminal then you have come to the right place. In this tutorial, I will teach you how to have the minimalistic terminal below available for you to write all your shell commands with a unique syntax-highlighting and auto-suggestion experience that makes shell scripting easier than it ever was.

The setup shown in this tutorial will allow you to install the necessary software and set up the environment for your programming. Once done, there are no limits to the amount of customization that can be done so feel free to explore around. Alright! Let’s get started πŸ₯³

Download and install iTerm2

iTerm2 is an emulator for macOS terminals and can be installed from their official site. Follow the instructions on the website to install iTerm2. Once this is done you can start using iTerm like your regular Mac Terminal. We will now install oh-my-zsh!

Install OH-MY-ZSH

This will change your terminal shell from bash to zsh which will allow you to add more functionalities and plug-ins later since zsh is more customizable. You can install it by visiting the official site or just paste the code below into your iTerm window.

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Install Powerline Fonts

To display the zsh customizations properly, power line patched fonts are required. You can install them from their official GitHub repo or you can use the shell commands below.

# Navigate to home directory
cd ~
# Clone the git repo
git clone https://github.com/powerline/fonts.git
# Navigate to the folder
cd fonts
# Run the script for installation
source ./install.sh

Once you finish the installation, you can delete the fonts folder from your home directory. Next, you need to go to iTerm2 (top left of the screen) > Preferences. Then click on Profiles and then select the Text tab. Under the font selector, choose any font with the word “power line” in it that appeals to you. I personally like to use Ubuntu Mono derivative for Powerline.

Install Material Design Theme for iTerm2

The material design theme can be installed from their official site. Once you download it, you will need to go into preferences of iTerm2 again and under the Profiles section, you can select the Colors tab and then import the theme by choosing the Color Presets dropdown.

Syntax-highlighting and Auto-suggestion Plug-ins

In order to install these plug-ins, you can run the following commands in your terminal.

git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

Once you do this you will need to open your .zshrc file and edit it. You can open the file with any text editor of your choice. .zshrc file lives in your home directory. In there you will see a line with plug-ins. You need to change that to make it look like the following.

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

Customizing Prompt

You can customize your prompt to show anything. It could be your username or the name of your computer. If you are like me and like to have an ASCII emoji, feel free to browse through these emojis here and then add the following lines at the bottom of your .zshrc file.

prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    # ADD YOUR TEXT OR EMOJI IN THE QUOTES BELOW
    prompt_segment black default "(◠﹏◠)"
  fi
}

What’s Next?

There is basically no limit to the customizations you can make with iTerm2 and zsh to your prompt. I would recommend scouring through ideas on iTerm’s official theme page.

There are also some nice-looking themes like draculatheme and powerlevel10k which are worth checking out!

Configuring VS Code Terminal

If you are a VSCode user, you might find that your terminal in there does not display properly. To fix that, you just need to change their terminal fonts in VSCode settings. To do that just go to settings (Cmd + ,) and search for “terminal font” and change the font to any powerline patched fonts.

VS Code Configuration

If you found this article helpful, consider subscribing to my mailing list where I send out bi-weekly emails about a variety of content. Every email is on a different topic ranging from tech tips, life advice, personal experiences and much more.

Processing…
Success! You're on the list.

One comment

  1. Oh-my-zsh is great but it’s really slow. Try giving zinit a try.

    It’s not as easy to setup tho

Leave a Reply