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
history # Show command historyctrl+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 commandDirectory Navigation
cd - # Go to previous directorycd ~-3 # Go to third most recently visited directorypushd /path # Push directory onto directory stackpopd # Pop directory from stackdirs -v # View directory stackCommand Expansion
<TAB> # Command/file/path completion (enhanced by plugins)ctrl+x h # Complete command from man page helpctrl+x a # Complete alias=ls # Expand to full path of executableGlobbing and Pattern Matching
ls *(.) # List only regular filesls *(/) # List only directoriesls *(*) # List only executable filesls *(@) # List only symlinksls *(Lk+100) # List files larger than 100KBls *(mh-1) # List files modified in the last hourls *~*.txt # List all files except .txt filesProcess Manipulation
ctrl+z # Suspend processfg # Resume suspended processjobs # List background jobs%1 # Reference job number 1%+ # Most recently suspended job%- # Second most recently suspended jobOh-My-ZSH Core Features
Configuration
$ZSH/custom # Directory for custom configs$ZSH_CUSTOM/themes # Custom themes directory$ZSH_CUSTOM/plugins # Custom plugins directoryomz update # Update Oh-My-ZSHomz theme list # List available themesomz theme set theme_name # Set themePlugin-Specific Commands
aliases
acs # Show all aliases in categorised formals [search-term] # Search for aliasaws
awsenv # Show AWS credentialsawsp # Switch AWS profilebrew
brews # List installed formulaebubo # Update Homebrew and outdated formulaebubc # Upgrade and clean upbfu # Upgrade brew formulaebun
bun # Bun runtimebunx # Execute packages with Bunbun add # Add dependenciesbun remove # Remove dependenciesbun run # Run scriptscommand-not-found
# Automatically suggests package to install when command not foundcommon-aliases
l # ls -lFhla # ls -lAFhlt # ls sorted by datella # ls -laFhmd # mkdir -prd # rmdir... # cd ../..dotenv
# Automatically loads .env files when entering a directoryeza (modern replacement for ls)
eza # Modern ls replacementeza -l # List in long formateza -T # Tree vieweza -a # Show hidden fileseza --icons # Show iconseza -s modified # Sort by modification timefzf (fuzzy finder)
ctrl+t # Paste selected files/dirs onto command linectrl+r # Search command history with fzfalt+c # cd into selected directory**<TAB> # Fuzzy completion for files and directoriesfzf-tab
<TAB> # Enhanced tab completion with fzf previewgh (GitHub CLI)
gh repo clone # Clone a repositorygh pr create # Create a pull requestgh issue create # Create an issuegh repo view # View a repositorygh auth login # Authenticate with GitHubgit
g # Alias for gitga # git addgc # git commit -vgco # git checkoutgd # git diffgst # git statusgl # git pullgp # git pushgrb # git rebasegm # git mergegbr # git branchgit-auto-fetch
# Automatically fetches git repositories periodically# Configure with: GIT_AUTO_FETCH_INTERVAL=1200 (seconds)history
h # Display historyhs [search-term] # Search historyhsi [search-term] # Case-insensitive searchnmap
nmap_open_ports # Scan for open ports on hostnmap_list_interfaces # List all network interfacesnmap_slow # Slow comprehensive scanrust
cargo # Rust package managerrustc # Rust compilerrustup # Rust toolchain installerstarship (prompt)
# Configure with ~/.config/starship.tomltmux
ta # Attach tmux sessiontad # Attach tmux session with directoryts # New tmux sessiontl # List tmux sessionszoxide (smarter cd command)
z dirname # Jump to a directory with fuzzy matchingzi dirname # Jump to directory with interactive selectionz - # Go to previous directoryzoxide query # Output the best match for a given queryzoxide add # Add a directory to zoxide databasezsh-autosuggestions
<right-arrow> # Accept suggestion<ctrl+e> # Accept suggestion (end of line)<ctrl+f> # Accept partial suggestionzsh-interactive-cd
cd <TAB> # Interactive directory navigation with fzfAdvanced ZSH Techniques
Aliases and Functions
# In your .zshrcalias gs='git status' # Simple aliasmyfunction() { # Define function echo "Hello, $1!"}Suffix Aliases
# In your .zshrcalias -s md=nvim # Open .md files with neovimalias -s {jpg,png}=open # Open images with default appGlobal Aliases
alias -g G='| grep' # Usage: ls G fooalias -g L='| less' # Usage: ls Lalias -g NE='2> /dev/null'# Redirect stderr to /dev/nullDirectory Aliases
hash -d proj=~/projects # Access with ~projZSH Options
# In your .zshrcsetopt AUTO_CD # Type directory name to cdsetopt EXTENDED_GLOB # Extended globbingsetopt HIST_IGNORE_DUPS # Don't save duplicate commandssetopt CORRECT # Command correctionsetopt AUTO_PUSHD # Auto pushd on cdKey Binding
# In your .zshrcbindkey '^[f' forward-word # Alt+f moves forward one wordbindkey '^[b' backward-word # Alt+b moves backward one wordbindkey "^P" up-line-or-searchbindkey "^N" down-line-or-searchCustom Configurations
Custom Plugins
# Clone custom plugin to $ZSH_CUSTOM/pluginsgit clone https://github.com/example/plugin.git $ZSH_CUSTOM/plugins/plugin# Add to plugins list in .zshrcplugins=(... plugin)Custom Theme
# Clone theme to $ZSH_CUSTOM/themesgit clone https://github.com/example/theme.git $ZSH_CUSTOM/themes/theme# Set in .zshrcZSH_THEME="theme"Starship Prompt
Configuration
# 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 = 3truncation_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
# Navigate with zoxidez projects
# Use fzf to find filenvim $(fzf)
# Use git commandsgstga .gc -m "Update code"gp
# Use GitHub CLIgh pr create
# Interactive directory navigationcd <TAB>
# AWS profile switchingawsp production
# Use Bun for JavaScript/TypeScriptbun add lodashbun run buildTips for Optimising Your ZSH Experience
- Regularly update Oh-My-ZSH with
omz update - Clean up your .zshrc by grouping related configurations
- Use
zprofto profile ZSH startup if it becomes slow - Consider using zinit, antigen, or antibody for plugin management if you have many plugins
- Customise Starship prompt for your specific workflow needs
- Create custom functions for repetitive tasks
- Add frequently used directories to zoxide with
zoxide add /path/to/dir - Use
ctrl+rwith fzf for efficient command history search - Leverage global aliases for common command patterns
- Configure fzf-tab for better preview options