aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Blechmann <tim@klingt.org>2024-01-20 11:32:13 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-01-26 15:29:11 +0000
commitfeaf0938191ae8759bd335dbae8d664a7151f6ae (patch)
tree0b1ae0fe02514fc8b9fb200f203c69e4920184cd
parent15147a6ee094d2c1da31450bdaf2874b63f441e3 (diff)
scripts: improve zsh support
`$(basename -- $0)` does not detect that a script is sourced when the shell is zsh Change-Id: I8ffede1023d5b70e244f0bb02032aaaa8f4e7dac Reviewed-by: Samuli Piippo <samuli.piippo@qt.io> (cherry picked from commit 640aff7564816ace466018943a8ea1287f3cab0c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rwxr-xr-xscripts/setup-environment.sh14
1 files changed, 11 insertions, 3 deletions
diff --git a/scripts/setup-environment.sh b/scripts/setup-environment.sh
index bda7a436..cecde10d 100755
--- a/scripts/setup-environment.sh
+++ b/scripts/setup-environment.sh
@@ -42,9 +42,17 @@ while test -n "$1"; do
done
THIS_SCRIPT="setup-environment.sh"
-if [ "$(basename -- $0)" = "${THIS_SCRIPT}" ]; then
- echo "Error: This script needs to be sourced. Please run as '. $0'"
- return 1
+
+if [[ $ZSH_EVAL_CONTEXT=="toplevel" || $ZSH_EVAL_CONTEXT=="toplevel:file" ]]; then
+ if [[ "$ZSH_EVAL_CONTEXT" == "toplevel" ]]; then
+ echo "Error: This script needs to be sourced. Please run as '. $0'"
+ return 1
+ fi
+else
+ if [ "$(basename -- $0)" = "${THIS_SCRIPT}" ]; then
+ echo "Error: This script needs to be sourced. Please run as '. $0'"
+ return 1
+ fi
fi
if [ -z "$MACHINE" ]; then