From 8365c8f954b2732be3ec9441f8464117d4c0cb93 Mon Sep 17 00:00:00 2001 From: Olcan Date: Mon, 2 Jun 2025 14:16:48 -0700 Subject: prefer to load gemini-specific .env file from .gemini folder when it exists there (#697) --- scripts/sandbox_command.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'scripts/sandbox_command.sh') diff --git a/scripts/sandbox_command.sh b/scripts/sandbox_command.sh index 7c140c61..325722f5 100755 --- a/scripts/sandbox_command.sh +++ b/scripts/sandbox_command.sh @@ -43,21 +43,31 @@ fi # if GEMINI_SANDBOX is not set, try to source .env in case set there # allow .env to be in any ancestor directory (same as findEnvFile in config.ts) +# prefer gemini-specific .env under .gemini folder (also same as in findEnvFile) if [ -z "${GEMINI_SANDBOX:-}" ]; then current_dir=$(pwd) dot_env_sourced=false while [ "$current_dir" != "/" ]; do - if [ -f "$current_dir/.env" ]; then + if [ -f "$current_dir/.gemini/.env" ]; then + source "$current_dir/.gemini/.env" + dot_env_sourced=true + break + elif [ -f "$current_dir/.env" ]; then source "$current_dir/.env" dot_env_sourced=true break fi current_dir=$(dirname "$current_dir") done - # if .env is not found in any ancestor directory, try ~/.env as fallback - if [ "$dot_env_sourced" = false ] && [ -f "$HOME/.env" ]; then - source "$HOME/.env" - dot_env_sourced=true + # if .env is not found in any ancestor directory, try home as fallback + if [ "$dot_env_sourced" = false ]; then + if [ -f "$HOME/.gemini/.env" ]; then + source "$HOME/.gemini/.env" + dot_env_sourced=true + elif [ -f "$HOME/.env" ]; then + source "$HOME/.env" + dot_env_sourced=true + fi fi fi -- cgit v1.2.3