(2020) ZSH iTerm2 Terminal Setup + OpenCV Hello World | [Python3][Oh My Zsh]
Tags: Opencv, Python3, Zsh, Learn To Code, Command Line

Overview

Z shell or Zsh incorporates some of the best features from bash, the Zsh shell was designed for interactive use with full customization. Zsh has become the recommended shell, when you combine zsh with iTerm2 and frameworks such as Oh My Zsh you can take your terminal experience to the next level. In this guide, I’m going to walk you through the essential steps to get up and running with zsh, using iTerm2. You’ll also have a chance to put zsh to use, I’ll get your environment ready for OpenCV development with python3.

Assumptions

You are running on a Mac with brew, and have a basic understanding of the terminal.

iTerm2 and Zsh Setup

First you need to install iTerm2. brew install iterm2 .

iTerm2 is a replacement for your standard terminal, it is fully configurable with many features such as split screen and profiles.

Brew is our package manager for MacOS, the cask command is an extension of home-brew that lets you install macOS apps.

Next, install zsh brew install zsh .

brew installation of zsh

Oh My Zsh

Once you have zsh, install Oh My Zsh by running the command sh -c “$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh

Oh My Zsh is a framework packed with functions, plugins and themes to extend your Zsh experience.

Ensure zsh is set to your default shell with the command chsh -s $(which zsh)

At this point you should start a new iTerm2 shell instance or run the command source ~/.zshrc to apply your configuration changes.

Zsh Recommended Plugins

Here are my recommended plugins to get you started.

Powerlevel10k (p10k) is a theme for Zsh with tons of customization options.

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

The zsh-autosuggestions plugin will use your history to suggest commands for you.

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

Zsh-syntax-highlighting, highlights commands as you type, it can be useful to ensure you are using the correct commands.

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

Edit .zshrc file

With our plugins cloned, now install micro, the terminal based text editor. curl https://getmic.ro | bash

micro installed

After the installation run micro ~/.zshrc , in the micro editor set the p10k theme.

set zsh_theme to p10k

now load your cloned plugins by added them to the plugins list.

enable zsh plugins

You will also want to enable autocorrection by uncommenting the line ENABLE_CORRECT=“true” .

Save and close your .zshrc file then reload it, source ~/.zshrc .

p10k Configuration

Now we can run the powerlevel10k configuration. p10k configure .

The p10k configuration will walk you through a number of customization options to help you create a unique terminal just for you.

p10k configuration process

At this point you’ve finished your zsh setup. Let’s put all of this to use by installing OpenCV with your new zsh setup.

OpenCV Setup

First check to see if you already have python installed with the command pip -V . If you already have python, check for updates pip install — upgrade pip.

If you do not have python installed, lets install python3, brew install python3 . Once installed, check your version python3 — version .

Next, install OpenCV, brew install opencv .

Now, open your IDE, we will create a small script that will open an image file using computer vision 2 (cv2).

Python Script

Create a .py file and enter the code below. For this example to work, you should include an image file for cv2 to read.

Run your script with python python3 myScriptName.py

Wrap Up ⚡️

Zsh is packed with features to help you harness the power of the terminal. Adding p10k customization and executing commands using iTerm2 opens a world of possibilities.

I hope you found this guide straightforward and easy to follow. If you have questions or just want to chat, I encourage you to join my discord.

Gist commands| Twitter | Instagram