ZSH Configuration
· 3 min read
A curated guide to supercharge your shell experience with ZSH and Oh My Zsh
🌟 Top Features
-
Smart Completion
- Case-insensitive matching
- Path completion with highlighting
- Command history suggestions
- Fuzzy search capabilities with fzf
-
Plugin System
- Git integration
- Syntax highlighting with advanced patterns
- Auto-suggestions
- Directory jumping with fzf
-
Modern Tools
- eza for beautiful ls output
- fzf for fuzzy finding
- Syntax highlighting with patterns
- Smart aliases
-
History Management
- Shared history across sessions
- Pattern search with fzf
- Timestamp tracking
- Duplicate removal
-
Directory Navigation
- Auto cd
- Directory stack
- Named directories
- Path abbreviation
🛠 Essential Configuration
# Core Settings
HISTSIZE=1000000
SAVEHIST=1000000
setopt EXTENDED_HISTORY
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_SAVE_NO_DUPS
# Completion System
autoload -Uz compinit
compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
# Load plugins first
plugins=(git git-flow zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
# FZF Configuration (after plugins)
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Enhanced FZF options
export FZF_DEFAULT_OPTS="--height 40% --layout=reverse --border --preview 'bat --style=numbers --color=always --line-range :500 {}'"
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview'"
# Initialize fzf widgets
autoload -U fzf-cd-widget
zle -N fzf-cd-widget
bindkey '^[c' fzf-cd-widget
autoload -U fzf-file-widget
zle -N fzf-file-widget
bindkey '^T' fzf-file-widget
autoload -U fzf-history-widget
zle -N fzf-history-widget
bindkey '^R' fzf-history-widget
# Modern ls with exa
alias ls='eza --icons --group-directories-first'
alias ll='eza -l --icons --group-directories-first --git'
alias la='eza -la --icons --group-directories-first --git'
alias lt='eza --tree --icons --level=2'
alias l.='eza -d .* --icons'
🔌 Must-Have Plugins
-
zsh-autosuggestions
- Command suggestions based on history
- Inline completion
- Custom suggestion strategy
- Fish-like experience
-
zsh-syntax-highlighting
- Command syntax highlighting
- Error indication
- Bracket matching
- Path validation
- Custom patterns and colors
-
fzf
- Fuzzy file finding
- History search
- Directory navigation
- Command completion
- Git integration
-
git
- Comprehensive Git aliases
- Branch information
- Status indicators
- Common operations shortcuts
🎨 Theme Customization
-
Framework Support
- Oh My Zsh
- Prezto
- Antigen
- Zinit
-
Popular Themes
- Powerlevel10k
- Agnoster
- Bureau
- Robbyrussell
-
Custom Elements
- Git status
- Python virtualenv
- Node.js version
- Exit status
💡 Pro Tips
-
Performance Optimization
# Lazy loading for slow commands
nvm() {
unset -f nvm
source ~/.nvm/nvm.sh
nvm "$@"
} -
Custom Functions
# Enhanced directory jumping with fzf
j() {
[ $# -gt 0 ] && _z "$*" && return
cd "$(z -l | fzf --height 40% --reverse --inline-info | sed 's/^[0-9,.]* *//')"
} -
Alias Management
# Modern git shortcuts
alias g='git status'
alias gco='git checkout'
alias gcp='git cherry-pick'
🚀 Getting Started
-
Installation
# Install ZSH
sudo apt install zsh
# Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Install essential tools
sudo apt install fzf exa -
Plugin Installation
# Auto-suggestions
git clone https://github.com/zsh-users/zsh-autosuggestions \${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# Syntax highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# fzf completion and key bindings
$(brew --prefix)/opt/fzf/install # On macOS
/usr/share/doc/fzf/install # On Linux
🔧 Maintenance
-
Regular Updates
# Update Oh My Zsh
omz update
# Update plugins
git -C \${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions pull
git -C \${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting pull -
Cleanup
# Clean command history
echo "" > ~/.zsh_history
# Rebuild completion cache
rm ~/.zcompdump*
compinit
🎯 Best Practices
-
Configuration Organization
- Keep main settings in ~/.zshrc
- Use ~/.zshenv for environment variables
- Create ~/.zsh/ for custom functions
- Maintain separate plugin configs
-
Performance Monitoring
- Use
zproffor profiling - Monitor startup time
- Lazy load heavy integrations
- Cache completion and other data
- Use
