How I set up my Terminal (Oh-my-zsh + Powerline9k + iTerm 2)
"This post show how I set up my Terminal (zsh, oh-my-zsh, iTerm 2/Terminal) on every machines I use for development."
Us developers spend lots and lots of time staring at our terminals (along with our IDE, of course). It makes sense to customize the way they look and feel to our liking. After all, having a colorful and good looking shell window can increase ones' productivity and dev skill by up to 500% which translate to over 9000+ business values!!!! (Just kidding, it was just a fun procrastinating thing to do while having an insomnia 😅).
Some plugins like the git plugin do have functional benefits for making sure that I am on the right branch and reminding me to push my code though.
Setting Up ZSH
ZSH
Many UNIX systems, including Ubuntu and macOS—prior to macOS Catalina, come with bash
as the default shell. zsh
offer most of the features bash
has and much more.
The most important quality-of-life improvement for me is its amazing autocomplete and approximate autocorrect functionality. Say, I execute an ssh
command with a bunch of parameters a couple weeks back and want to run the same command again weeks later, in bash
I either have to type the whole thing again (and trying to remember the destination's IP Address) or scroll through a bunch of commands history. With zsh
I can type ssh
then press arrow up and zsh
will only show commands in the history starting with ssh
.
Its folder name autocompletion, command lookup and such are also much better. The list of features zsh
has is too long to list here so you will just have to try it yourself!
For the most part, zsh
will function much the same as bash
as far as compatability go. However, it does have some little quirks here and there that you may encouter (e.g. different behavior with very long curl
command or having to use source script.sh
instead of . script.sh
).
macOS
Since macOS Catalina, Apple has replaced the default shell—bash
shell—with zsh
.
For users running older version of macOS, go to System Preferences > Users & Group then right click on your user then click Advance.
In the pop-up window, change the Login shell to /bin/zsh
.
Windows 10
For Windows 10, I strongly recommend using WSL 2. It will allow you to run actual Linux shell on Windows. Instructions on how to configure zsh
on WSL 2 depends on the distro.
For Ubuntu based distro, you can use these commands to install zsh
:
sudo apt-get install wget curl git
sudo apt install zsh
and this command to make it the default shell:
chsh -s $(which zsh)
Linux
For those of you Linux users... well I'm sure you already know what you are doing. 😂
OH-MY-ZSH
oh-my-zsh
is an open-source framework for managing zsh configurations. We will be using it mainly to set our themeing options here.
Ref: https://ohmyz.sh/#install
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Powerline9k Theme
Powerline9k is the theme I will be using with my shell. You can find more themes by searching for "oh-my-zsh themes".
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
Powerline Fonts
The Powerline9k theme (and many other themes) uses some special characters (e.g. the arrow looking character) that are non-standard. These font packs are designed specifically for uses with themes like these. You can install them using the quick install command below or manually by visiting this link.
Ref: https://github.com/powerline/fonts
# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts
This will:
- Clone/download the fonts from the official GitHub repo.
cd
into the downloaded folder and execute the installation scriptinstall.sh
.- Delete the downloaded folder.
iTerm 2
For macOS users, I recommend using iTerm 2, which you can download here. It supports a bunch more features than the default Terminal.app, but more importantly, richer color!
Settings:
Appearance
This setting dictate how the app window will look.
iTerm 2 > Preferences > Appearance > Theme: Minimal
Profiles:
This setting is where you adjust the look of your actual console (font family, font size, text color, background color, etc.).
For my exact profile, download this JSON file and import it into iTerm 2 using Other Actions... > Import JSON Profiles... and select the file you have just downloaded.
Windows 10 Terminal
For Windows 10 users, I recommend using the new Terminal app for Windows released by Microsoft.
.zshrc
The ~/.zshrc
is a script that will run everytime zsh
start. This is where you can configure your zsh
and oh-my-zsh
to your liking.
Below is my current ~/.zshrc
:
# Path to your oh-my-zsh installation.
export ZSH="/Users/woods/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
// highlight-next-line
# 1.
ZSH_THEME="powerlevel9k/powerlevel9k"
# ...
# git plugin
plugins=(git)
source $ZSH/oh-my-zsh.sh
# ========================================================================
# My own customization:
# ========================================================================
// highlight-next-line
# 2.
# POWERLEVEL9K
# --------------------------
DEFAULT_USER=woods
VIRTUAL_ENV_DISABLE_PROMPT=1
# These configurations are for the
# powerlevel9k theme's promt
POWERLEVEL9K_ANACONDA_BACKGROUND=yellow
POWERLEVEL9K_DIR_SHOW_WRITABLE=true
POWERLEVEL9K_ALWAYS_SHOW_USER=true
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda virtualenv context dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time)
# How many levels to show (2: "../parent/current")
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
// highlight-next-line
# 3.
# Shortcuts:
# --------------------------
alias code='open -a "Visual Studio Code"'
alias code-insiders='open -a "Visual Studio Code - Insiders"'
- This is where you can select the theme you want to use. The theme I use here is the
powerlevel9k
that I installed earlier. - These lines are specifically for the
powerlevel9k
theme. They tell the theme what to display on left and right promts and such. - These are general shortcut I create to open a file in Visual Studio Code/Visual Studio Code - Insiders. You can set more
alias
here as you wish.