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.
This commit is contained in:
Zahary Karadjov 2022-10-15 00:59:16 +03:00
parent b1d380e07e
commit dc535cd462
No known key found for this signature in database
GPG Key ID: C1F42EAFF38D570F

View File

@ -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