hailo-ai / hailo-rpi5-examples

MIT License
387 stars 59 forks source link

setup_env.sh cannot be sourced with zsh #48

Open segabor opened 2 months ago

segabor commented 2 months ago

If I try to source setup_env.sh in my RPi 5 using zsh, I get the following error,

➜  hailo-rpi5-examples git:(main) ✗ echo $ZSH_VERSION 
5.9
➜  hailo-rpi5-examples git:(main) ✗ . ./setup_env.sh          
is_sourced:2: no such option: sourced
This script needs to be sourced to correctly set up the environment. Please run '. setup_env.sh' instead of executing it.
➜  hailo-rpi5-examples git:(main) ✗ 

I fixed the script so I can now use it with zsh. See the patch below,

diff --git a/setup_env.sh b/setup_env.sh
index d19faa6..4b900c0 100755
--- a/setup_env.sh
+++ b/setup_env.sh
@@ -11,7 +11,7 @@ TAPPAS_REQUIRED_VERSION=("3.28.0" "3.28.1" "3.28.2" "3.29.0" "3.29.1")
 # Function to check if the script is being sourced
 is_sourced() {
     if [ -n "$ZSH_VERSION" ]; then
-        [[ -o sourced ]]
+        case $ZSH_EVAL_CONTEXT in *:file:*) return 0;; esac 
     elif [ -n "$BASH_VERSION" ]; then
         [[ "${BASH_SOURCE[0]}" != "$0" ]]
     else
SamuelHudec commented 1 week ago

can someone from Hailo merge 👆 ?