From dc535cd4627e6c1ec023ee6d6d0c3e5d66d414e5 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sat, 15 Oct 2022 00:59:16 +0300 Subject: [PATCH] Better compatibility with direnv Scripts sourcing a project env.sh file (e.g. direnv's .envrc) can specify the `NBS_ONLY_LOAD_ENV_VARS` env variable to avoid any attempts from NBS to execute a target script. Previously, the script was trying to detect only sourcing from an interactive shell. --- scripts/env.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/env.sh b/scripts/env.sh index 9e9b2d1..d2298ff 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -68,12 +68,14 @@ $EXPORT_FUNC add_submodule export NIMBUS_BUILD_SYSTEM=yes -if [[ $# == 1 && $1 == "bash" ]]; then - # the only way to change PS1 in a child shell, apparently - # (we're not getting the original PS1 value in here, so set a complete and nice prompt) - export PS1="[Nimbus env] \[\033[0;31m\]\l \[\033[1;33m\]\d \[\033[1;36m\]\t \[\033[0;32m\]|\w|\[\033[0m\]\n\u\$ " - exec "$1" --login --noprofile -else - # can't use "exec" here if we're getting function names as params - "$@" +if [[ ! -n "$NBS_ONLY_LOAD_ENV_VARS" ]]; then + if [[ $# == 1 && $1 == "bash" ]]; then + # the only way to change PS1 in a child shell, apparently + # (we're not getting the original PS1 value in here, so set a complete and nice prompt) + export PS1="[Nimbus env] \[\033[0;31m\]\l \[\033[1;33m\]\d \[\033[1;36m\]\t \[\033[0;32m\]|\w|\[\033[0m\]\n\u\$ " + exec "$1" --login --noprofile + else + # can't use "exec" here if we're getting function names as params + "$@" + fi fi