Skip to content

zsh

ZSH or Z-Shell is a Unix shell that is designed to be compatible with the Bourne shell (sh).

Core ZSH Features

Command History

Terminal window
history # Show command history
ctrl+r # Search command history (fzf enhances this)
!! # Execute previous command
!$ # Last argument of previous command
!foo # Execute last command starting with 'foo'
!foo:p # Print last command starting with 'foo'
!* # All arguments of previous command
^foo^bar # Replace 'foo' with 'bar' in previous command

Directory Navigation

Terminal window
cd - # Go to previous directory
cd ~-3 # Go to third most recently visited directory
pushd /path # Push directory onto directory stack
popd # Pop directory from stack
dirs -v # View directory stack

Command Expansion

Terminal window
<TAB> # Command/file/path completion (enhanced by plugins)
ctrl+x h # Complete command from man page help
ctrl+x a # Complete alias
=ls # Expand to full path of executable

Globbing and Pattern Matching

Terminal window
ls *(.) # List only regular files
ls *(/) # List only directories
ls *(*) # List only executable files
ls *(@) # List only symlinks
ls *(Lk+100) # List files larger than 100KB
ls *(mh-1) # List files modified in the last hour
ls *~*.txt # List all files except .txt files

Process Manipulation

Terminal window
ctrl+z # Suspend process
fg # Resume suspended process
jobs # List background jobs
%1 # Reference job number 1
%+ # Most recently suspended job
%- # Second most recently suspended job

Oh-My-ZSH Core Features

Configuration

Terminal window
$ZSH/custom # Directory for custom configs
$ZSH_CUSTOM/themes # Custom themes directory
$ZSH_CUSTOM/plugins # Custom plugins directory
omz update # Update Oh-My-ZSH
omz theme list # List available themes
omz theme set theme_name # Set theme

Plugin-Specific Commands

aliases

Terminal window
acs # Show all aliases in categorised form
als [search-term] # Search for alias

aws

Terminal window
awsenv # Show AWS credentials
awsp # Switch AWS profile

brew

Terminal window
brews # List installed formulae
bubo # Update Homebrew and outdated formulae
bubc # Upgrade and clean up
bfu # Upgrade brew formulae

bun

Terminal window
bun # Bun runtime
bunx # Execute packages with Bun
bun add # Add dependencies
bun remove # Remove dependencies
bun run # Run scripts

command-not-found

Terminal window
# Automatically suggests package to install when command not found

common-aliases

Terminal window
l # ls -lFh
la # ls -lAFh
lt # ls sorted by date
lla # ls -laFh
md # mkdir -p
rd # rmdir
... # cd ../..

dotenv

Terminal window
# Automatically loads .env files when entering a directory

eza (modern replacement for ls)

Terminal window
eza # Modern ls replacement
eza -l # List in long format
eza -T # Tree view
eza -a # Show hidden files
eza --icons # Show icons
eza -s modified # Sort by modification time

fzf (fuzzy finder)

Terminal window
ctrl+t # Paste selected files/dirs onto command line
ctrl+r # Search command history with fzf
alt+c # cd into selected directory
**<TAB> # Fuzzy completion for files and directories

fzf-tab

Terminal window
<TAB> # Enhanced tab completion with fzf preview

gh (GitHub CLI)

Terminal window
gh repo clone # Clone a repository
gh pr create # Create a pull request
gh issue create # Create an issue
gh repo view # View a repository
gh auth login # Authenticate with GitHub

git

Terminal window
g # Alias for git
ga # git add
gc # git commit -v
gco # git checkout
gd # git diff
gst # git status
gl # git pull
gp # git push
grb # git rebase
gm # git merge
gbr # git branch

git-auto-fetch

Terminal window
# Automatically fetches git repositories periodically
# Configure with: GIT_AUTO_FETCH_INTERVAL=1200 (seconds)

history

Terminal window
h # Display history
hs [search-term] # Search history
hsi [search-term] # Case-insensitive search

nmap

Terminal window
nmap_open_ports # Scan for open ports on host
nmap_list_interfaces # List all network interfaces
nmap_slow # Slow comprehensive scan

rust

Terminal window
cargo # Rust package manager
rustc # Rust compiler
rustup # Rust toolchain installer

starship (prompt)

Terminal window
# Configure with ~/.config/starship.toml

tmux

Terminal window
ta # Attach tmux session
tad # Attach tmux session with directory
ts # New tmux session
tl # List tmux sessions

zoxide (smarter cd command)

Terminal window
z dirname # Jump to a directory with fuzzy matching
zi dirname # Jump to directory with interactive selection
z - # Go to previous directory
zoxide query # Output the best match for a given query
zoxide add # Add a directory to zoxide database

zsh-autosuggestions

Terminal window
<right-arrow> # Accept suggestion
<ctrl+e> # Accept suggestion (end of line)
<ctrl+f> # Accept partial suggestion

zsh-interactive-cd

Terminal window
cd <TAB> # Interactive directory navigation with fzf

Advanced ZSH Techniques

Aliases and Functions

Terminal window
# In your .zshrc
alias gs='git status' # Simple alias
myfunction() { # Define function
echo "Hello, $1!"
}

Suffix Aliases

Terminal window
# In your .zshrc
alias -s md=nvim # Open .md files with neovim
alias -s {jpg,png}=open # Open images with default app

Global Aliases

Terminal window
alias -g G='| grep' # Usage: ls G foo
alias -g L='| less' # Usage: ls L
alias -g NE='2> /dev/null'# Redirect stderr to /dev/null

Directory Aliases

Terminal window
hash -d proj=~/projects # Access with ~proj

ZSH Options

Terminal window
# In your .zshrc
setopt AUTO_CD # Type directory name to cd
setopt EXTENDED_GLOB # Extended globbing
setopt HIST_IGNORE_DUPS # Don't save duplicate commands
setopt CORRECT # Command correction
setopt AUTO_PUSHD # Auto pushd on cd

Key Binding

Terminal window
# In your .zshrc
bindkey '^[f' forward-word # Alt+f moves forward one word
bindkey '^[b' backward-word # Alt+b moves backward one word
bindkey "^P" up-line-or-search
bindkey "^N" down-line-or-search

Custom Configurations

Custom Plugins

Terminal window
# Clone custom plugin to $ZSH_CUSTOM/plugins
git clone https://github.com/example/plugin.git $ZSH_CUSTOM/plugins/plugin
# Add to plugins list in .zshrc
plugins=(... plugin)

Custom Theme

Terminal window
# Clone theme to $ZSH_CUSTOM/themes
git clone https://github.com/example/theme.git $ZSH_CUSTOM/themes/theme
# Set in .zshrc
ZSH_THEME="theme"

Starship Prompt

Configuration

~/.config/starship.toml
# Minimal example - customize as needed
format = """
[](#3A3A3A)\
$username\
$hostname\
$directory\
$git_branch\
$git_status\
$rust\
$nodejs\
$bun\
$aws\
$cmd_duration\
$line_break\
$character"""
[directory]
style = "blue"
truncation_length = 3
truncation_symbol = "…/"
[character]
success_symbol = "[➜](green)"
error_symbol = "[✗](red)"
[git_branch]
format = "[$symbol$branch]($style) "
symbol = "🌱 "
style = "green"
[git_status]
format = '([\[$all_status$ahead_behind\]]($style) )'
style = "red"
[cmd_duration]
format = "[$duration]($style) "
style = "yellow"

Full ZSH Workflow Example

Terminal window
# Navigate with zoxide
z projects
# Use fzf to find file
nvim $(fzf)
# Use git commands
gst
ga .
gc -m "Update code"
gp
# Use GitHub CLI
gh pr create
# Interactive directory navigation
cd <TAB>
# AWS profile switching
awsp production
# Use Bun for JavaScript/TypeScript
bun add lodash
bun run build

Tips for Optimising Your ZSH Experience

  1. Regularly update Oh-My-ZSH with omz update
  2. Clean up your .zshrc by grouping related configurations
  3. Use zprof to profile ZSH startup if it becomes slow
  4. Consider using zinit, antigen, or antibody for plugin management if you have many plugins
  5. Customise Starship prompt for your specific workflow needs
  6. Create custom functions for repetitive tasks
  7. Add frequently used directories to zoxide with zoxide add /path/to/dir
  8. Use ctrl+r with fzf for efficient command history search
  9. Leverage global aliases for common command patterns
  10. Configure fzf-tab for better preview options

Useful Resources