diff --git a/.zshrc b/.zshrc index 77b5f43..d406442 100644 --- a/.zshrc +++ b/.zshrc @@ -28,12 +28,16 @@ add_to_path() { } # Source a file with existence and readability check (zsh-friendly) -# Usage: source_file /path/to/file +# Usage: source_file /path/to/file [export] +# Pass 'export' as second arg to auto-export all variables via set -a/+a. source_file() { local file="$1" + local export_vars="${2:-}" if [[ -f "$file" && -r "$file" ]]; then + [[ "$export_vars" == "export" ]] && set -a source "$file" + [[ "$export_vars" == "export" ]] && set +a fi } @@ -83,19 +87,6 @@ for expr in "${eval_expressions[@]}"; do done -# ============================================================================= -# ENVIRONMENT VARIABLES -# ============================================================================= - -# Source ~/.env with set -a so every variable is automatically exported -# and inherited by child processes (scripts, subshells, etc.). -if [[ -f "$HOME/.env" && -r "$HOME/.env" ]]; then - set -a - source "$HOME/.env" - set +a -fi - - # ============================================================================= # CONFIGURATION FILES TO SOURCE # ============================================================================= @@ -108,6 +99,9 @@ source_files=( "$HOME/.p10k.zsh" ) +# Source ~/.env with auto-export so variables reach child processes +source_file "$HOME/.env" export + # Source zsh-compatible files (skip if missing, no warnings) for config_file in "${source_files[@]}"; do source_file "$config_file"