# ░█▀█░█▀█░▀█▀░█░█░█▀▀ # ░█▀▀░█▀█░░█░░█▀█░▀▀█ # ░▀░░░▀░▀░░▀░░▀░▀░▀▀▀ # Intelligent PATH management with existence checking and deduplication # Ensure we have a clean slate for PATH manipulation typeset -U path PATH # Remove duplicates automatically # Define potential paths in priority order declare -a potential_paths=( "$HOME/bin" # Personal scripts "$HOME/.local/bin" # User-installed binaries "/opt/homebrew/bin" # Homebrew (Apple Silicon) "/opt/homebrew/sbin" # Homebrew system binaries "/usr/local/bin" # Homebrew (Intel) "/usr/local/sbin" # System binaries "/opt/homebrew/opt/python@3.13/libexec/bin" # Python 3.13 "/opt/homebrew/opt/python@3.12/libexec/bin" # Python 3.12 (fallback) "$HOME/.cargo/bin" # Rust binaries "/opt/homebrew/opt/gnu-sed/libexec/gnubin" # GNU sed "/opt/homebrew/opt/gnu-tar/libexec/gnubin" # GNU tar "/opt/homebrew/opt/coreutils/libexec/gnubin" # GNU coreutils ) # Build PATH intelligently build_path() { local new_paths=() # Add existing paths that we want to keep for existing_path in "${path[@]}"; do case "$existing_path" in # Skip paths we're going to add explicitly "$HOME/bin"|"$HOME/.local/bin"|"/opt/homebrew"*|"/usr/local"*|"$HOME/.cargo/bin") ;; # Keep system paths and others *) new_paths+=("$existing_path") ;; esac done # Add our curated paths (only if they exist) for check_path in "${potential_paths[@]}"; do if [[ -d "$check_path" ]]; then new_paths=("$check_path" "${new_paths[@]}") fi done # Rebuild PATH path=("${new_paths[@]}") } # Execute PATH building build_path # Verify critical tools are accessible verify_path() { local critical_tools=(git zsh python3 brew) local missing_tools=() for tool in "${critical_tools[@]}"; do if ! command -v "$tool" >/dev/null 2>&1; then missing_tools+=("$tool") fi done if (( ${#missing_tools[@]} > 0 )); then echo "⚠️ Missing critical tools: ${missing_tools[*]}" echo "💡 Consider running: brew install ${missing_tools[*]}" fi } # Run verification only in interactive shells [[ $- == *i* ]] && verify_path # MANPATH configuration for enhanced man pages if [[ -d "/opt/homebrew/share/man" ]]; then export MANPATH="/opt/homebrew/share/man:$MANPATH" fi # Info path for GNU info pages if [[ -d "/opt/homebrew/share/info" ]]; then export INFOPATH="/opt/homebrew/share/info:$INFOPATH" fi