The implementation
The detail page preserves the practical behavior of the original route: the writeup stays readable, the source remains copyable and syntax highlighted, and the item can still link back into the rest of the catalog.
zsh-config.sh
1#!/bin/zsh
2# Modern ZSH Configuration - Modular Architecture & Productivity Patterns
3# This is a condensed version focusing on patterns you can adopt
4
5#----------------------------------
6# 1. MODULAR ARCHITECTURE PATTERN
7#----------------------------------
8# Main ~/.zshrc loads configuration in specific order:
9# 1. Base settings (history, navigation, completion)
10# 2. PATH management (organized by category)
11# 3. External tool initialization
12# 4. Sourced files (aliases, improvements, secrets)
13# 5. Plugin loading (order matters - syntax highlighting last)
14
15# Example structure:
16# ~/.zshrc - Main configuration
17# ~/.zsh_aliases - Command aliases and functions
18# ~/.zsh_secrets - API keys, tokens (gitignored)
19# ~/.zsh_help.md - Comprehensive help documentation
20
21#----------------------------------
22# 2. ESSENTIAL ZSH OPTIONS
23#----------------------------------
24# History Configuration
25HISTSIZE=50000
26SAVEHIST=50000
27setopt HIST_IGNORE_ALL_DUPS # Remove older duplicate entries
28setopt HIST_REDUCE_BLANKS # Remove superfluous blanks
29setopt SHARE_HISTORY # Share history between sessions
30setopt EXTENDED_HISTORY # Record timestamps
31
32# Directory Navigation
33setopt AUTO_CD # Type directory name to cd
34setopt AUTO_PUSHD # Make cd push old directory to stack
35setopt PUSHD_IGNORE_DUPS # Don't push duplicates
36DIRSTACKSIZE=8 # Limit directory stack size
37
38# Completion Improvements
39setopt MENU_COMPLETE # Cycle through completions with tab
40setopt COMPLETE_IN_WORD # Complete from both ends of word
41zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # Case-insensitive
42zstyle ':completion:*' menu select # Interactive menu
43
44#----------------------------------
45# 3. PATH MANAGEMENT BEST PRACTICES
46#----------------------------------
47# Set base PATH first
48export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
49
50# Add paths by category (easier to maintain)
51# Package managers
52export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
53
54# User binaries
55export PATH="$HOME/.local/bin:$HOME/bin:$PATH"
56
57# Development tools
58export PATH="$HOME/.cargo/bin:$PATH"
59export PATH="$HOME/go/bin:$PATH"
60
61# Remove duplicates from PATH
62typeset -U PATH path
63
64#----------------------------------
65# 4. MODERN CLI TOOL REPLACEMENTS
66#----------------------------------
67# File system navigation with icons and git integration
68alias ls="eza --icons"
69alias ll="eza -la --icons"
70alias la="eza -a --icons"
71alias lt="eza --tree --icons"
72alias lsg="eza -la --git --icons"
73
74# Better system monitoring
75alias top='btop' # Beautiful TUI system monitor
76alias df='duf' # Modern disk usage viewer
77alias cat='bat' # Syntax highlighting, git integration
78
79# Ripgrep for fast searching
80alias rg='rg --smart-case' # Smart case by default
81alias rgf='rg --files' # List files
82alias rgi='rg --no-ignore' # Include ignored files
83alias rgh='rg --hidden' # Search hidden files
84
85# Database CLI improvements
86alias psql='pgcli' # PostgreSQL with auto-completion
87alias sql='usql' # Universal SQL client
88
89#----------------------------------
90# 5. PRODUCTIVITY ALIASES & FUNCTIONS
91#----------------------------------
92# Quick navigation
93alias ..='cd ..'
94alias ...='cd ../..'
95alias ....='cd ../../..'
96
97# Configuration shortcuts
98alias reload='source ~/.zshrc'
99alias zshconfig='${EDITOR:-nano} ~/.zshrc'
100alias aliasconfig='${EDITOR:-nano} ~/.zsh_aliases'
101
102# Git productivity
103alias git-hash="git log -1 --format=%h"
104alias lg="lazygit" # Interactive Git UI
105alias ghpr="gh pr create --base main -f -a @me"
106
107# SQL formatter function
108format-sql() {
109 if [ -z "$1" ]; then
110 echo "Usage: format-sql <file.sql>"
111 return 1
112 fi
113 pg_format -s 2 "$1" > "$1.formatted" && mv "$1.formatted" "$1"
114 echo "Formatted: $1"
115}
116
117#----------------------------------
118# 6. INTERACTIVE HELP SYSTEM
119#----------------------------------
120# Create a comprehensive help system using markdown and glow
121help() {
122 if [ -z "$1" ]; then
123 # Show interactive help menu
124 echo "Help topics: nav, fzf, git, tools, sql, aws"
125 echo "Usage: help <topic> or press Enter for full docs"
126 read -r choice
127
128 if [ -z "$choice" ]; then
129 glow -p ~/.zsh_help.md
130 else
131 help "$choice"
132 fi
133 else
134 # Jump to specific section
135 case "$1" in
136 nav) section="## 🧭 Navigation" ;;
137 fzf) section="## 🔍 FZF" ;;
138 git) section="## 🛠️ Git" ;;
139 tools) section="## 📁 File System Tools" ;;
140 sql) section="## 📀 SQL and Database" ;;
141 aws) section="## 🚀 AWS EC2 Management" ;;
142 *) section="## .*$1" ;;
143 esac
144 glow ~/.zsh_help.md | less -R +/"$section"
145 fi
146}
147
148#----------------------------------
149# 7. FZF PRODUCTIVITY
150#----------------------------------
151# FZF provides these keybindings by default:
152# Ctrl+R - Fuzzy search command history
153# Ctrl+T - Fuzzy search files and insert path
154# Alt+C - Fuzzy search and cd to directory
155
156# Custom FZF functions
157# Find and edit file
158fe() {
159 local file
160 file=$(fzf --preview 'bat --style=numbers --color=always {}')
161 [ -n "$file" ] && ${EDITOR:-vim} "$file"
162}
163
164# Find and cd to directory
165fd() {
166 local dir
167 dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m)
168 [ -n "$dir" ] && cd "$dir"
169}