diff options
author | Tim Blechmann <tim@klingt.org> | 2024-01-20 11:32:13 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-01-26 15:29:11 +0000 |
commit | 45e0f150d0b43a2e7484101b03bb42505eaf95a7 (patch) | |
tree | 4f7646be6bf98c1c17f66d577d7eca57535d4289 | |
parent | 1825ab1cbc680fb4ea67492f7b8accd19a668e33 (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-x | scripts/setup-environment.sh | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/scripts/setup-environment.sh b/scripts/setup-environment.sh index b4199e6f..34fed49b 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 |