Skip to content

Instantly share code, notes, and snippets.

@theamanbhargava
Created June 16, 2025 21:47
Show Gist options
  • Select an option

  • Save theamanbhargava/012cd640db9a1959fc6a277c621afc3e to your computer and use it in GitHub Desktop.

Select an option

Save theamanbhargava/012cd640db9a1959fc6a277c621afc3e to your computer and use it in GitHub Desktop.
Ultimate Mac ZSH config

Ultimate Mac Zsh Configuration Guide

Prerequisites

  1. Install Homebrew (if not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install required tools:
# Install Oh My Zsh (framework for managing zsh configuration)
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Install additional tools
brew install zsh-autosuggestions zsh-syntax-highlighting fzf bat eza ripgrep thefuck
brew install --cask font-meslo-lg-nerd-font

Configuration File (~/.zshrc)

Replace your ~/.zshrc with the following configuration:

# Path to your oh-my-zsh installation
export ZSH="$HOME/.oh-my-zsh"

# Set theme - Powerlevel10k is highly recommended
ZSH_THEME="robbyrussell" # Change to "powerlevel10k/powerlevel10k" after installing

# Uncomment the following line to use case-sensitive completion
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion
HYPHEN_INSENSITIVE="true"

# Uncomment the following line to enable command auto-correction
ENABLE_CORRECTION="true"

# Display red dots whilst waiting for completion
COMPLETION_WAITING_DOTS="true"

# Plugins
plugins=(
    git
    docker
    kubectl
    npm
    python
    macos
    vscode
    web-search
    copypath
    copyfile
    copybuffer
    dirhistory
    history
    jsontools
    sudo
)

source $ZSH/oh-my-zsh.sh

# User configuration

# Set default editor
export EDITOR='vim'

# History configuration
HISTFILE=~/.zsh_history
HISTSIZE=50000
SAVEHIST=50000
setopt EXTENDED_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_VERIFY
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY

# Directory navigation
setopt AUTO_CD
setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_SILENT

# Completion
setopt COMPLETE_IN_WORD
setopt ALWAYS_TO_END
setopt MENU_COMPLETE
setopt AUTO_MENU

# Load zsh-autosuggestions
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh

# Load zsh-syntax-highlighting
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# FZF configuration
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*"'
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'

# Aliases - General
alias zshconfig="$EDITOR ~/.zshrc"
alias ohmyzsh="$EDITOR ~/.oh-my-zsh"
alias reload="source ~/.zshrc"
alias cl="clear"

# Aliases - Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias ~="cd ~"
alias -- -="cd -"

# Aliases - Enhanced commands
alias ls="eza --icons --group-directories-first"
alias ll="eza -alh --icons --group-directories-first"
alias la="eza -a --icons --group-directories-first"
alias lt="eza --tree --icons -a -I '.git|node_modules|.cache'"
alias cat="bat --style=plain --paging=never"
alias grep="grep --color=auto"
alias df="df -h"
alias du="du -h"

# Aliases - Git (additional to oh-my-zsh git plugin)
alias gs="git status"
alias gd="git diff"
alias gl="git log --oneline --graph --decorate"
alias gla="git log --oneline --graph --decorate --all"
alias gco="git checkout"
alias gcm="git commit -m"
alias gp="git push"
alias gpu="git pull"
alias gst="git stash"
alias gstp="git stash pop"

# Aliases - Development
alias python="python3"
alias pip="pip3"
alias serve="python -m http.server 8000"
alias ports="lsof -i -P | grep LISTEN"

# Aliases - System
alias update="brew update && brew upgrade && brew cleanup"
alias cleanup="find . -type f -name '*.DS_Store' -ls -delete"
alias showfiles="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
alias hidefiles="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"
alias flushdns="sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder"

# Functions

# Create a new directory and enter it
mkd() {
    mkdir -p "$@" && cd "$_"
}

# Change to the directory and list contents
cdl() {
    cd "$1" && ll
}

# Extract any archive
extract() {
    if [ -f $1 ]; then
        case $1 in
            *.tar.bz2)   tar xjf $1     ;;
            *.tar.gz)    tar xzf $1     ;;
            *.bz2)       bunzip2 $1     ;;
            *.rar)       unrar e $1     ;;
            *.gz)        gunzip $1      ;;
            *.tar)       tar xf $1      ;;
            *.tbz2)      tar xjf $1     ;;
            *.tgz)       tar xzf $1     ;;
            *.zip)       unzip $1       ;;
            *.Z)         uncompress $1  ;;
            *.7z)        7z x $1        ;;
            *)           echo "'$1' cannot be extracted" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

# Quick backup of a file
backup() {
    cp "$1" "$1.backup-$(date +%Y%m%d-%H%M%S)"
}

# Search for a string in files
search() {
    rg --color=always --line-number --no-heading "$@" | fzf --ansi
}

# Kill process by port
killport() {
    lsof -ti:$1 | xargs kill -9
}

# Weather
weather() {
    curl "wttr.in/${1:-}"
}

# Enable thefuck
eval $(thefuck --alias)

# Load local configuration if it exists
[ -f ~/.zshrc.local ] && source ~/.zshrc.local

# Path additions
export PATH="/usr/local/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"

# Node Version Manager (if installed)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

# Ruby Version Manager (if installed)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

# pyenv (if installed)
if command -v pyenv 1>/dev/null 2>&1; then
    eval "$(pyenv init -)"
fi

Setup Instructions

  1. Backup your existing configuration:
cp ~/.zshrc ~/.zshrc.backup
  1. Create the new configuration:
# Copy the configuration above to your ~/.zshrc file
vim ~/.zshrc
# Paste the configuration and save
  1. Install FZF key bindings:
$(brew --prefix)/opt/fzf/install
  1. Apply the configuration:
source ~/.zshrc

Optional: Install Powerlevel10k Theme

For an even better visual experience:

# Install Powerlevel10k
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

# Update ZSH_THEME in ~/.zshrc
sed -i '' 's/ZSH_THEME="robbyrussell"/ZSH_THEME="powerlevel10k\/powerlevel10k"/' ~/.zshrc

# Reload zsh
source ~/.zshrc

# Follow the configuration wizard that appears
p10k configure

Key Features Explained

Productivity Boosters

  • Auto-suggestions: Start typing and see command suggestions based on history
  • Syntax highlighting: Commands are colored to show validity
  • FZF integration: Fuzzy search through files and command history (Ctrl+R)
  • Smart aliases: Shorter commands for common operations
  • The Fuck: Type fuck after a failed command to get corrections

Enhanced Commands

  • lseza: Better file listing with icons
  • catbat: Syntax highlighting for file viewing
  • grepripgrep: Faster searching through files

Useful Functions

  • mkd <dir>: Create and enter directory
  • extract <file>: Extract any archive type
  • backup <file>: Quick timestamped backup
  • search <term>: Search files with preview
  • killport <port>: Kill process using specific port
  • weather [location]: Get weather report

Navigation Shortcuts

  • .., ..., ....: Go up directories
  • -: Go to previous directory
  • Auto-cd: Type directory name to cd into it

Customization Tips

  1. Add custom aliases: Add them to the aliases section or create ~/.zshrc.local
  2. Change theme: Modify ZSH_THEME variable
  3. Add plugins: Add to the plugins array
  4. Modify prompt: Use Powerlevel10k for extensive customization

Troubleshooting

  • Slow startup: Comment out unused plugins
  • Font issues: Install and set Nerd Font in terminal preferences
  • Command not found: Ensure Homebrew paths are correct
  • Permission issues: Check file permissions with ls -la ~/.zshrc

This configuration provides a modern, feature-rich terminal experience that will significantly boost your productivity!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment