DEV Community

Cover image for iTerm2 + Oh My Zsh! + Powerlevel10K best terminal combination for Geeks!
Camilo Martinez
Camilo Martinez

Posted on • Originally published at Medium on

iTerm2 + Oh My Zsh! + Powerlevel10K best terminal combination for Geeks!

There is a before and after listening to these letters together: ZSH. You may wonder: Why did not I hear about this before? D’oh!

Oh My Zsh - a delightful & open-source framework for Z-Shell

ZSH (Z Shell) it’s a real evolution, modernize terminal things with simple solutions. It can be used on GNU Linux and macOS, but I will teach you how to install and configure it on MacOS.

Prerequisites

Homebrew

Brew has his own classification. The inside brew can found the CLI app and utilities. Inside is cask all the application with Graphical Interface.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Add this lines to ~/.bash_profile and/or ~/.zshrc file:

# Brew
export BREW_HOME="/opt/homebrew/bin"
export PATH="$BREW_HOME:$PATH"
eval "$($BREW_HOME/brew shellenv)"
Enter fullscreen mode Exit fullscreen mode

Run this commands on terminal:

eval "$(/opt/homebrew/bin/brew shellenv)"
source ~/.zshrc
source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Restart your terminal, then update and upgrade brew sources:

brew tap homebrew/cask-fonts
brew update --force --quiet
brew upgrade
brew cleanup
Enter fullscreen mode Exit fullscreen mode
https://brew.sh — usage: https://docs.brew.sh/FAQ

Run this command, and follow doctor recommendations:

brew doctor
Enter fullscreen mode Exit fullscreen mode

The Triplets of Belleville

WARNING: I don’t want presume, but iTerm2 + Oh My Zsh! + Powerlevel10K it’s a lethal combination. You will not want to use another terminal later.

brew install --cask iterm2 

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

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

git clone https://github.com/nobeans/zsh-sdkman.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/sdkman
git clone https://github.com/zsh-users/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/Pilaton/OhMyZsh-full-autoupdate.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ohmyzsh-full-autoupdate

chsh -s /bin/zsh
Enter fullscreen mode Exit fullscreen mode

Close the default terminal and open iTerm2.

Configuration

ZSH configuration file is located under ~/.zshrc. Open with your favorite editor and set:

DEFAULT_USER="$USER"

ZSH_THEME="powerlevel10k/powerlevel10k"
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(history)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1

export LS_COLORS="rs=0:no=00:mi=00:mh=00:ln=01;36:or=01;31:di=01;34:ow=04;01;34:st=34:tw=04;34:pi=01;33:so=01;33:do=01;33:bd=01;33:cd=01;33:su=01;35:sg=01;35:ca=01;35:ex=01;32:"

ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor root line)
ZSH_HIGHLIGHT_PATTERNS=('rm -rf *' 'fg=white,bold,bg=red')

plugins=(
  brew
    command-not-found
    extract
    macos 
    git 
    github 
    gitignore 
    sdkman 
    history-substring-search 
    node 
    npm 
    volta
    vscode
    sudo
    web-search
    z
    zsh-autosuggestions
    zsh-syntax-highlighting
    ohmyzsh-full-autoupdate
)

# Z Plugin
if command -v brew >/dev/null 2>&1; then
  # Load rupa's z if installed
  [ -f $(brew --prefix)/etc/profile.d/z.sh ] && source $(brew --prefix)/etc/profile.d/z.sh
fi
source /opt/homebrew/etc/profile.d/z.sh

# Plugins
source /opt/homebrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
Enter fullscreen mode Exit fullscreen mode

Add all the plugins that you want or need inside plugins=() list, each one in a new line.

Open iTerm2 and after changing the value make sure to update your ~/.zshrc file running the complete command:

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

Fonts

Download and Install Meslo and Nerd Fonts

brew install --cask font-meslo-lg-nerd-font
brew install --cask font-hack-nerd-font
Enter fullscreen mode Exit fullscreen mode

Change it on iTerm > Settings > Profiles > Text > Change Font and select MesloLGS NF.

Visual Studio Code

If you want use ZSH as default terminal in Visual Studio Code, add this settings (⌘ + ,):

"terminal.external.osxExec": "iTerm.app",
"terminal.integrated.fontFamily": "Meslo LG M for Powerline",
"terminal.integrated.defaultProfile.osx": "zsh",
Enter fullscreen mode Exit fullscreen mode

Wizard

On the first run, Powerlevel10k configuration wizard will ask you a few questions and configure your prompt.

If it doesn't trigger automatically, type p10k configure.

Wizard

Configuration wizard creates ~/.p10k.zsh based on your preferences. Additional prompt customization can be done by editing this file. It has plenty of comments to help you navigate through configuration options.

Terminal (Bash)

macOS default terminal comes with version 3 and not going to update it because the newer version changes his license. Apple does not supply any software under the GPLv3.

Open default terminal and run this command in order to use an updated version:

brew install bash bash-completion
Enter fullscreen mode Exit fullscreen mode

Add this line to ~/.bash_profile file:

[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
Enter fullscreen mode Exit fullscreen mode

Open terminal and change Terminal > Settings > General on Shell open with: select Command (complete path) and set /bin/bash value.

With this configuration, now you can use ZSH on iTerm2 and Bash on default Terminal.

Remove “Last login:”

For me, it's unnecessary and annoying the default “Last login:” message in the macOS terminal. Happily, it's easy:

touch ~/.hushlogin
Enter fullscreen mode Exit fullscreen mode

Become a ZSH Ninja!

Highly recommend taking this FREE course made by @WesBoss:

Bonus Track


That’s All Folks!
Happy Coding 🖖

beer

Top comments (20)

Collapse
 
gabrielizalo profile image
Gabriel Porras

The Brew installation chaged. Nos this is the command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
equiman profile image
Camilo Martinez

Fixed. Thanks for reporting the update! 🤘

Collapse
 
iolivares profile image
Iván Olivares Rojas

Thanks for this!

if you have a 404 problem to install the fonts, search here the solution: github.com/Homebrew/homebrew-cask-...

$ brew tap homebrew/cask-fonts         # You only need to do this once!
Enter fullscreen mode Exit fullscreen mode
Collapse
 
gunt profile image
gunt • Edited

hi Camilo,

Thank you for this powerful config.

I'm getting this exact same problem as the user suggest here

superuser.com/questions/1061181/it...

I'm not getting the colors theme.

Do you know how to fix it?

Thx.

Collapse
 
equiman profile image
Camilo Martinez

Hi Gunt, I have no idea.

Can you try with powerlevel10k. See comments below.

And run p10k config command. It's like a wizard configuration.

Maybe this can help. Let us know if works.

Collapse
 
gunt profile image
gunt

I try with powerlevel10k, I love it already, but the theme colors are not working. I'm still trying to fix it. I will let you know.

Collapse
 
romkatv profile image
Roman Perepelitsa

There is powerlevel10k now. It's 10 times faster than powerlevel9k and backward-compatible with its configs. You can switch theme without changing any of your POWERLEVEL9K options to keep the same prompt you are used to while making it blazingly fast.

First, clone powerlevel10k.

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

Then set ZSH_THEME=powerlevel10k/powerlevel10k in your ~/.zshrc and restart zsh.

Collapse
 
equiman profile image
Camilo Martinez • Edited

Wow I watched the video and it's amazing.
Works like a charm and p10k configure command is the best.

Thanks!

Collapse
 
gabrielizalo profile image
Gabriel Porras

Hello,

The initial command: brew tap caskroom/cask is not working anymore.

Thanks for this step by step.

Collapse
 
equiman profile image
Camilo Martinez

You welcome.

I'll fix that. I see on documentation that on new versions don't need to install cask anymore, you just need homebrew.

Thanks!

Collapse
 
gabrielizalo profile image
Gabriel Porras

If you can update with PowerLevel10k. It's amazing.

Thread Thread
 
equiman profile image
Camilo Martinez

I'll add it as a bonus.

I'm using it actually and it's really fast.

Thread Thread
 
equiman profile image
Camilo Martinez

@gabrielizalo finally was updated to powerlevel10k

Collapse
 
jef profile image
Jef LeCompte

I know this is an old one now, but take a look at prezto and powerlevel10k. You might like the results!

Collapse
 
dbelyaeff profile image
Dmitriy Belyaev

Camilo, thank you so much!

I'd been using iTerm + zsh for a years, but even that I've found out something new for me from your post.

Collapse
 
equiman profile image
Camilo Martinez

Your welcome Dmitriy, do the free course I learned a lot.

Collapse
 
jpsingh10 profile image
Jashanpreet Singh

what theme are using for iterm2? what about the syntax highlighting

Collapse
 
equiman profile image
Camilo Martinez

I'm using Powerlevel9k theme: github.com/Powerlevel9k/powerlevel9k

and Syntax Highlight installed with brew:

brew install zsh-syntax-highlighting

Collapse
 
jpsingh10 profile image
Jashanpreet Singh

I’m talking about the interm2 color scheme, not the oh-my-zsh, sorry for the confusion

Thread Thread
 
equiman profile image
Camilo Martinez • Edited

No problem, that's my Appearance configuration:

iTerm Preferences