#!/usr/bin/env zsh # Safe shell configuration reload with conflict resolution # Embodies μέτρον: thoughtful, measured approach to shell management set -euo pipefail DOTFILES_DIR="$HOME/dotfiles" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' echo -e "${YELLOW}🔧 Safe Shell Configuration Reload${NC}" echo "Following prime directive: durable solutions over expedient fixes" echo "" # Step 1: Clear conflicting aliases echo "1️⃣ Clearing potential conflicts..." unalias cd chamber 2>/dev/null || true echo " ✅ Aliases cleared" # Step 2: Load in proper order with error handling echo "2️⃣ Loading configuration modules..." # Environment first (sets foundation) if source "$DOTFILES_DIR/shell/environment.zsh" 2>/dev/null; then echo " ✅ Environment loaded" else echo -e " ${RED}❌ Environment failed${NC}" exit 1 fi # Paths second (builds PATH properly) if source "$DOTFILES_DIR/shell/paths.zsh" 2>/dev/null; then echo " ✅ Paths loaded" else echo -e " ${RED}❌ Paths failed${NC}" exit 1 fi # Functions third (defines utilities) if source "$DOTFILES_DIR/shell/functions.zsh" 2>/dev/null; then echo " ✅ Functions loaded" else echo -e " ${RED}❌ Functions failed - attempting repair${NC}" # Attempt repair: comment out problematic functions echo " 🔧 Attempting automatic repair..." # Create backup cp "$DOTFILES_DIR/shell/functions.zsh" "$DOTFILES_DIR/shell/functions.zsh.backup.$(date +%Y%m%d_%H%M%S)" # Temporarily disable chamber function sed -i.tmp 's/^chamber()/# chamber() # DISABLED/' "$DOTFILES_DIR/shell/functions.zsh" if source "$DOTFILES_DIR/shell/functions.zsh" 2>/dev/null; then echo " ✅ Functions loaded (chamber disabled)" echo " 📝 Chamber function disabled - investigate separately" else echo -e " ${RED}❌ Functions still failing${NC}" # Restore backup mv "$DOTFILES_DIR/shell/functions.zsh.backup.$(date +%Y%m%d_%H%M%S)" "$DOTFILES_DIR/shell/functions.zsh" exit 1 fi fi # Aliases last (safe to override) if source "$DOTFILES_DIR/shell/aliases.zsh" 2>/dev/null; then echo " ✅ Aliases loaded" else echo -e " ${YELLOW}⚠️ Aliases had issues - continuing${NC}" fi echo "" echo -e "${GREEN}✅ Shell configuration successfully reloaded${NC}" echo "🎯 Test your sysupdate function now" # Test critical functions echo "" echo "3️⃣ Testing critical functions..." if declare -f sysupdate >/dev/null; then echo " ✅ sysupdate function available" else echo -e " ${RED}❌ sysupdate not found${NC}" fi if declare -f detect_context >/dev/null; then echo " ✅ detect_context function available" else echo -e " ${YELLOW}⚠️ detect_context not found${NC}" fi