Skip to content

Zsh Shell Guide

Zsh (Z Shell) is a powerful shell that extends bash with many additional features. It’s especially popular thanks to Oh My Zsh, a community-driven framework for managing Zsh configuration.

Enhanced Completion

  • Intelligent tab completion
  • Cursor-based menu selection
  • Expandable abbreviations

Plugins & Themes

  • Oh My Zsh framework
  • Thousands of plugins
  • Hundreds of themes

Advanced Features

  • Shared history between sessions
  • Globbing improvements
  • Spelling correction

macOS

Terminal window
# Install via Homebrew
brew install zsh
# Set as default shell
chsh -s /bin/zsh

Ubuntu/Debian

Terminal window
sudo apt install zsh
# Set as default
chsh -s /usr/bin/zsh

Verify

Terminal window
echo $SHELL
Terminal window
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  • Location: ~/.zshrc
Terminal window
omz update
File Purpose
~/.zshrc Main configuration file
~/.zprofile Login shell config
~/.zshenv Always sourced
~/.zlogin After .zprofile
Terminal window
# Edit ~/.zshrc
plugins=(
git
docker
python
pip
kubectl
zsh-autosuggestions
zsh-syntax-highlighting
)

zsh-autosuggestions

  • Suggests commands as you type
  • Based on history
  • Install: git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

zsh-syntax-highlighting

  • Syntax highlighting for commands
  • Red for invalid, green for valid
  • Install: git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

z

  • Quick directory jumping
  • Based on frecency (frequent + recent)
Plugin Description
git Git aliases and functions
docker Docker completions
kubectl Kubernetes completions
pip Python pip completions
python Python virtualenv support
npm npm completions
brew Homebrew completions
Terminal window
# Shortcuts
alias ll='eza -lah'
alias la='eza -a'
alias l='eza -l'
# Git
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gco='git checkout'
# Navigation
alias ..='cd ..'
alias ...='cd ../..'
# Safety
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
Terminal window
# Create and cd into directory
function mkcd() {
mkdir -p "$1" && cd "$1"
}
# Extract archives
extract() {
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "'$1' cannot be extracted" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
Terminal window
# In ~/.zshrc
ZSH_THEME="robbyrussell"
Theme Description
robbyrussell Default, simple and clean
agnoster Powerline-style, requires font
powerlevel10k Highly customizable, popular
starship Fast, cross-shell
Terminal window
# Install
git clone --depth=1 https://github.com/romkatv/powerlevel10k ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
# Set in ~/.zshrc
ZSH_THEME="powerlevel10k/powerlevel10k"
# Configure
p10k configure
Shortcut Action
Ctrl+A Move to beginning
Ctrl+E Move to end
Ctrl+U Clear line before
Ctrl+K Clear line after
Ctrl+R Search history
Ctrl+O Accept and run
Alt+. Insert last argument
Esc+Q Push current line to stack
Ctrl+X,G Insert all completions
Terminal window
# In ~/.zshrc
export PATH="$HOME/bin:$PATH"
export EDITOR=vim
export VISUAL=vim
# History settings
export HISTSIZE=10000
export SAVEHIST=10000
export HISTFILE=~/.zsh_history
Terminal window
# Recursive search
ls **/*.txt
# Case-insensitive
ls -l (**).txt
Terminal window
# Shared history (enable in ~/.zshrc)
setopt SHARE_HISTORY
setopt HIST_IGNORE_DUPS
Terminal window
# Enable
setopt CORRECT
setopt CORRECT_ALL
Terminal window
# In ~/.zshrc
setopt AUTO_CD # cd by typing directory
setopt AUTO_PUSHD # Push directory to stack
setopt AUTO_LIST # Automatically list choices
setopt MENU_COMPLETE # Auto-insert first match
setopt HIST_IGNORE_ALL_DUPS # No duplicate commands
setopt SHARE_HISTORY # Share history between sessions
Terminal window
# In ~/.zshrc
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
Terminal window
zstyle ':completion:*' menu select
Terminal window
DISABLE_AUTO_UPDATE="true"