Skip to content

Instantly share code, notes, and snippets.

@EconoBen
Created June 29, 2025 06:24
Show Gist options
  • Select an option

  • Save EconoBen/86b5d3c5b5a6ec9283ae63bcdf555b4f to your computer and use it in GitHub Desktop.

Select an option

Save EconoBen/86b5d3c5b5a6ec9283ae63bcdf555b4f to your computer and use it in GitHub Desktop.
[workshop] category:shell tags:zsh,productivity,shell-config - Modern ZSH Configuration System
#!/bin/zsh
# Modern ZSH Configuration - Modular Architecture & Productivity Patterns
# This is a condensed version focusing on patterns you can adopt
#----------------------------------
# 1. MODULAR ARCHITECTURE PATTERN
#----------------------------------
# Main ~/.zshrc loads configuration in specific order:
# 1. Base settings (history, navigation, completion)
# 2. PATH management (organized by category)
# 3. External tool initialization
# 4. Sourced files (aliases, improvements, secrets)
# 5. Plugin loading (order matters - syntax highlighting last)
# Example structure:
# ~/.zshrc - Main configuration
# ~/.zsh_aliases - Command aliases and functions
# ~/.zsh_secrets - API keys, tokens (gitignored)
# ~/.zsh_help.md - Comprehensive help documentation
#----------------------------------
# 2. ESSENTIAL ZSH OPTIONS
#----------------------------------
# History Configuration
HISTSIZE=50000
SAVEHIST=50000
setopt HIST_IGNORE_ALL_DUPS # Remove older duplicate entries
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks
setopt SHARE_HISTORY # Share history between sessions
setopt EXTENDED_HISTORY # Record timestamps
# Directory Navigation
setopt AUTO_CD # Type directory name to cd
setopt AUTO_PUSHD # Make cd push old directory to stack
setopt PUSHD_IGNORE_DUPS # Don't push duplicates
DIRSTACKSIZE=8 # Limit directory stack size
# Completion Improvements
setopt MENU_COMPLETE # Cycle through completions with tab
setopt COMPLETE_IN_WORD # Complete from both ends of word
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # Case-insensitive
zstyle ':completion:*' menu select # Interactive menu
#----------------------------------
# 3. PATH MANAGEMENT BEST PRACTICES
#----------------------------------
# Set base PATH first
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
# Add paths by category (easier to maintain)
# Package managers
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
# User binaries
export PATH="$HOME/.local/bin:$HOME/bin:$PATH"
# Development tools
export PATH="$HOME/.cargo/bin:$PATH"
export PATH="$HOME/go/bin:$PATH"
# Remove duplicates from PATH
typeset -U PATH path
#----------------------------------
# 4. MODERN CLI TOOL REPLACEMENTS
#----------------------------------
# File system navigation with icons and git integration
alias ls="eza --icons"
alias ll="eza -la --icons"
alias la="eza -a --icons"
alias lt="eza --tree --icons"
alias lsg="eza -la --git --icons"
# Better system monitoring
alias top='btop' # Beautiful TUI system monitor
alias df='duf' # Modern disk usage viewer
alias cat='bat' # Syntax highlighting, git integration
# Ripgrep for fast searching
alias rg='rg --smart-case' # Smart case by default
alias rgf='rg --files' # List files
alias rgi='rg --no-ignore' # Include ignored files
alias rgh='rg --hidden' # Search hidden files
# Database CLI improvements
alias psql='pgcli' # PostgreSQL with auto-completion
alias sql='usql' # Universal SQL client
#----------------------------------
# 5. PRODUCTIVITY ALIASES & FUNCTIONS
#----------------------------------
# Quick navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
# Configuration shortcuts
alias reload='source ~/.zshrc'
alias zshconfig='${EDITOR:-nano} ~/.zshrc'
alias aliasconfig='${EDITOR:-nano} ~/.zsh_aliases'
# Git productivity
alias git-hash="git log -1 --format=%h"
alias lg="lazygit" # Interactive Git UI
alias ghpr="gh pr create --base main -f -a @me"
# SQL formatter function
format-sql() {
if [ -z "$1" ]; then
echo "Usage: format-sql <file.sql>"
return 1
fi
pg_format -s 2 "$1" > "$1.formatted" && mv "$1.formatted" "$1"
echo "Formatted: $1"
}
#----------------------------------
# 6. INTERACTIVE HELP SYSTEM
#----------------------------------
# Create a comprehensive help system using markdown and glow
help() {
if [ -z "$1" ]; then
# Show interactive help menu
echo "Help topics: nav, fzf, git, tools, sql, aws"
echo "Usage: help <topic> or press Enter for full docs"
read -r choice
if [ -z "$choice" ]; then
glow -p ~/.zsh_help.md
else
help "$choice"
fi
else
# Jump to specific section
case "$1" in
nav) section="## 🧭 Navigation" ;;
fzf) section="## πŸ” FZF" ;;
git) section="## πŸ› οΈ Git" ;;
tools) section="## πŸ“ File System Tools" ;;
sql) section="## πŸ“€ SQL and Database" ;;
aws) section="## πŸš€ AWS EC2 Management" ;;
*) section="## .*$1" ;;
esac
glow ~/.zsh_help.md | less -R +/"$section"
fi
}
#----------------------------------
# 7. FZF PRODUCTIVITY
#----------------------------------
# FZF provides these keybindings by default:
# Ctrl+R - Fuzzy search command history
# Ctrl+T - Fuzzy search files and insert path
# Alt+C - Fuzzy search and cd to directory
# Custom FZF functions
# Find and edit file
fe() {
local file
file=$(fzf --preview 'bat --style=numbers --color=always {}')
[ -n "$file" ] && ${EDITOR:-vim} "$file"
}
# Find and cd to directory
fd() {
local dir
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m)
[ -n "$dir" ] && cd "$dir"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment