vxh.viet
6/8/2018 - 5:49 AM

Use iTerm and ZSH as Terminal Replacement

Use iTerm and ZSH as Terminal Replacement

Setup, iTerm ColorScheme, ZSH Theme,

First install Homebrew

1. Install iTerm2:

Next install iTerm2 with this:

# install iTerm
brew cask install iterm2

2. Install zsh and Oh My zsh:

Then install the zsh, an alternative to bash. The alternative to ~/.basrc is ~./zshrc, which you add extra scripts to that run when loading the terminal. (Mac OSX already come with zsh but it is really outdated, we use the version from brew instead):

# install zsh
brew install zsh

Oh my zsh is a framework for managing your zsh configuration. To install it use the below command:

# install oh my zsh
curl -L http://install.ohmyz.sh | sh

3. Install syntax highlighting:

One of the cool things you can add with it is syntax highlighting:

# add syntax highlighting
cd ~/.oh-my-zsh && git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
echo 'source ~/.oh-my-zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> ~/.zshrc

4. Install iTerm theme:

Now to install theme for iTerm, go to iTerm ColorScheme and download the zip file. To install, follow this:

  • Launch iTerm 2. Get the latest version at iterm2.com
  • Type CMD+i
  • Navigate to Colors tab
  • Click on Load Presets
  • Click on Import
  • Select the .itermcolors file(s) of the scheme(s) you'd like to use
  • Click on Load Presets and choose a color scheme.

Current favorite themes are these one:

- Earthsong (current one with swapped Green Normal - Cyan Bright and modified cursor color).
- Afterglow.
- Birds Of Paradise.
- Fideloper.
- Later This Evening.
- Sea Shells.
- Sea Foam Pastel.
- Slate.

5. Other Setting for iTerm:

Add this to ~/.zshrc so that it can recognize your existing alias and environment path:

source ~/.bash_profile

To change default open iTerm window size go to Preferences > Profile > Window > Setting for new Window and increase Columns and Rows.

To hide scrollbar go to Preferences > Appearance > Hide Scrollbars.

6. Change zsh theme to Powerlevel9k:

To change zsh theme go to Oh My ZSH theme or zsh theme.

But for now we will use Powerlevel9k:

# install powerlevel9k theme
git clone https://github.com/bhilburn/powerlevel9k.git ~/powerlevel9k
echo 'source  ~/powerlevel9k/powerlevel9k.zsh-theme' >> ~/.zshrc

In order for Powerlevel9k to work, we need to install Nerd font. We will use the patched Source Code Pro Regular.

Download this file (download all if necessary):

Sauce Code Pro Nerd Font Complete.ttf

Double click and select Install. After that select it in:

iTerm -> Preferences -> Profiles -> Text -> Font -> Change Font

After that add this line to ~/.zshrc SOURCE:

POWERLEVEL9K_MODE='nerdfont-complete'

7. Customize Powerlevel9k:

SOURCE

Add these to ~/.zshrc:

POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(user dir rbenv vcs)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2

NOTE: All these theme settings should be called before setting the theme or it wont take effect, example:

POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(user dir rbenv vcs)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2

source  ~/powerlevel9k/powerlevel9k.zsh-theme