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

Camilo Martinez - Sep 25 '18 - - Dev Community

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')

POWERLEVEL9K_INSTANT_PROMPT=quiet
POWERLEVEL9K_INSTANT_PROMPT=off

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:

CheatSheet (Key Shortcuts)

The common MacOS modifier keys are:

Command Control Option Shift

By default, word jumps and word deletions do not work. To enable these, go to iTerm > Settings > Profiles > Keys > Load Presets… and select Natural Text Editing.

Basic Actions

Shortcut Function
+ or + Word jumps
+ backspace Word deletion
+ d Delete current character
backspace Delete previous character
+ - Undo
+ backspace Entire line deletion
+ k Clear entire screen

Moving Faster

Function Shortcut
+ a Move to the start of line
+ e Move to the end of line
+ f Move forward a word
+ b Move backward a word

Copy and Paste

Function Shortcut
+ k Copy from cursor to the end of line
+ d Copy from cursor to the end of word
+ backspace Copy from cursor to the start of word
+ w Copy from cursor to previous whitespace
+ w Paste the last copied text
+ y Loop through and paste previously copy text
+ . Loop through and paste the last argument of previous commands

Tabs & Windows

Function Shortcut
+ Enter Fullscreen
+ Left Arrow Previous Tab
+ Right Arrow Next Tab
+ Number Go to Tab
+ + Number Go to Window
+ + Arrow Go to Split Pane by Direction
+ ] or + [ Go to Split Pane by Order of Use
+ + d Split Window Horizontally (same profile)
+ d Split Window Vertically (same profile)
+ + + h Split Window Horizontally (new profile)
+ + + v Split Window Vertically (new profile)
+ + m Set Mark
+ + j Jump to Mark

Bonus Track


That’s All Folks!
Happy Coding 🖖

beer

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player