diff options
author | Yannis Damigos <ydamigos@iccs.gr> | 2016-03-01 12:31:29 +0200 |
---|---|---|
committer | Gerrit Code Review <gerrit@zephyrproject.org> | 2016-03-02 12:32:58 +0000 |
commit | 3e3e297719fa7998bab8212e075c6ccc67ccdcfd (patch) | |
tree | 4bd927370b511756a5dc5c5a17bcf76b2ea4128e /zephyr-env.sh | |
parent | 9055bfe58fab10a1f33a73245c8fc058848fd9e8 (diff) |
zephyr-env.sh: Fixed sourcing the project environment file
In zsh the value of $0 depends on the FUNCTION_ARGZERO option
which is set by default. FUNCTION_ARGZERO, when it is set, sets
$0 temporarily to the name of the function/script when executing
a shell function or sourcing a script. POSIX_ARGZERO option,
when it is set, exposes the original value of $0 in spite of the
current FUNCTION_ARGZERO setting.
This patch allows to source the project environment file from
both zsh and bash. It also removes the -z option from the
basename command which is missing in OS X.
Change-Id: I5a32404784d9064bf749fa58b4d73d4b56c908c2
Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
Diffstat (limited to 'zephyr-env.sh')
-rw-r--r-- | zephyr-env.sh | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/zephyr-env.sh b/zephyr-env.sh index 40b20a568..3722f7729 100644 --- a/zephyr-env.sh +++ b/zephyr-env.sh @@ -14,7 +14,24 @@ # limitations under the License. # -if [ "X$(basename -z -- "$0")" "==" "Xzephyr-env.sh" ]; then +# In zsh the value of $0 depends on the FUNCTION_ARGZERO option which is +# set by default. FUNCTION_ARGZERO, when it is set, sets $0 temporarily +# to the name of the function/script when executing a shell function or +# sourcing a script. POSIX_ARGZERO option, when it is set, exposes the +# original value of $0 in spite of the current FUNCTION_ARGZERO setting. +if [ -n "$ZSH_VERSION" ]; then + if [ $options[posixargzero] != "on" ]; then + setopt posixargzero + NAME=$(basename -- "$0") + setopt posixargzero + else + NAME=$(basename -- "$0") + fi +else + NAME=$(basename -- "$0") +fi + +if [ "X$NAME" "==" "Xzephyr-env.sh" ]; then echo "Source this file (do NOT execute it!) to set the Zephyr Kernel environment." exit fi |