From e28db7a2fd2d14acf91f3896581e0c3c5c149be8 Mon Sep 17 00:00:00 2001 From: Simon Landrault Date: Tue, 1 Sep 2020 17:01:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8(bin)=20autoexport=20variables=20if?= =?UTF-8?q?=20source=20when=20activating?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the bin/activate command is started with source (or leading `.`), the export of environment variables will be automatically executed. --- bin/activate | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/activate b/bin/activate index 3ef10ed4..9953a59d 100755 --- a/bin/activate +++ b/bin/activate @@ -55,6 +55,7 @@ function select_release(){ function activate_release(){ declare release="$1" + declare -i is_sourced="$2" release_path="${RELEASES_ROOT}/${release}" env_file_path="${release_path}/${ENV_FILENAME}" @@ -69,15 +70,22 @@ function activate_release(){ exit 21 fi - echo -e "\\n# Copy/paste ${release} environment:" - cat "${env_file_path}" + if [[ ${is_sourced} -eq 1 ]]; then + source ${env_file_path} + echo -e "\\n# Following variables are now exported:" + cat "${env_file_path}" + else + echo -e "\\n# Copy/paste ${release} environment:" + cat "${env_file_path}" - echo -e "\\n# Or run the following command:" - echo -e ". ${env_file_path}" + echo -e "\\n# Or run the following command:" + echo -e ". ${env_file_path}" + fi - echo -e "\\n# Check your environment with:" + echo -e "\\n# You can check your environment with:" echo -e "make info" } release=$(select_release) -activate_release "${release}" +(return 2> /dev/null) && sourced=1 || sourced=0 +activate_release "${release}" "${sourced}"