Sometimes, using the default terminal sucks. You want to go out of the ordinary, to add life to the boring terminal and improve your productivity.
In this walk-through, we will configure iTerm2 with ZSH and its dependencies. This is a no-brainer, and after this, you’ll ponder the reason for not discovering ZSH earlier. Well, since you’re here already, let’s kick-start this.
Z shell (Zsh) is a Unix shell built on top of bash (the default shell for macOS) with a large number of improvements.
Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS.
Before installing Homebrew, we need to install the CLI tools for Xcode. Open your terminal and run the command:
xcode-select —-install
If you get an error, run xcode-select -r
to reset xcode-select.
Then, install Homebrew.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
iTerm2 is a replacement for terminal and the successor to iTerm. Most software engineers prefer iTerm2 over the default terminal that ships with macOS as a result of its cool features. You can integrate zsh into iTerm2 to increase productivity.
To install iTerm2, run the command:
brew cask install iterm2
Zsh is a shell designed for interactive use, although it is also a powerful scripting language.
By default, macOS ships with zsh located in /bin/zsh
. Let’s install zsh using brew and make iTerm2 use it.
brew install zsh
“Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. It will not make you a 10x developer…but you might feel like one” — Robby Russell
It runs on Zsh to provide cool features configurable within the ~/.zhrc
config file. Install Oh My Zsh by running the command
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Check the installed version
zsh --version
You can upgrade it to get the latest features it offers.
upgrade_oh_my_zsh
Restart iTerm2 to dive into the new experience of using Zsh. Welcome to the “Oh My Zsh” world 😄.
That’s not all. Now, we will install the dependencies to get the best out of Zsh.
Oh My Zsh comes bundled with a lot of themes. The default theme is robbyrussell, but you can change it to any theme of your choice. In this scenario, I changed it to agnoster, an already pre-installed theme.
You need to set this theme in your ~/.zshrc
config file. To open the config file (.zshrc), run the command: nano ~/.zshrc
Or open the file in a text editor with open ~/.zshrc
Set the zsh theme
ZSH_THEME="agnoster"
and update your changes source ~/.zshrc
To install another theme not pre-installed, clone the repository into custom/themesdirectory. In this scenario, we’ll install powerlevel9k,
$ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
Then, select this theme in your .zshrc file
ZSH_THEME="powerlevel9k/powerlevel9k"
Update your changes by running the command source ~/.zshrc
Navigate to iTerm2 > Preferences > Profiles > Colors
if you wish to change the background color of the terminal.
The selected theme in this scenario requires powerline fonts. So, let’s install that.
I will be using Inconsolata. Get your preferred font out of these powerline fonts. Then, download and install it.
Or download the entire font.
git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh
To change the font, navigate to iTerm2 > Preferences > Profiles > Text > Change Font
.
Now, you can see Inconsolata listed as one of the fonts. Select your preferred font. For fonts that support ligatures like Fira Code, check the “Use ligatures” option to view your arrows and other operators in a stylish manner like ( → ).
Let’s change the color scheme to bring out the beauty of our terminal. Navigate to iTerm2-Color-Schemes and download the ZIP folder. Then, extract the downloaded folder cos what we need resides in the schemes folder.
Navigate to iTerm2 > Preferences > Profile > Colors > Color Presets > Import
Tada! 🎉 We’re done with the basic settings.
Oh My ZSH comes preloaded with a git plugin. To add more, for instance, docker, auto-suggestion, syntax highlighting and more:
git clone https://github.com/zsh-users/zsh-docker.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-docker
open ~/.oh-my-zsh
and navigate to .oh-my-zsh > custom > plugins
directory to view the cloned directory.~/.zshrc
config fileplugins=(
git
docker
zsh-syntax-highlighting
zsh-autosuggestions
)
source ~/.zshrc
Aliases are shortcuts used to reduce the time spent on typing commands. To add aliases to commands you use frequently, navigate to the aliases section within the .zshrc file and add the aliases
alias gs="git status"
alias gp="git push"
For a complete guide on configuring and using aliases, read my article on Aliases. You can go a step further to create a custom message on your terminal
If you know about other means of improving productivity using ZSH, you can reach out to me on Twitter. I will be glad to hear from you.
I write about accessibility, performance, JavaScript and workflow tooling. If my articles have helped or inspired you in your development journey, or you want me to write more, consider supporting me.