setup_esp_idf__latest_stable__linux_macos.fish 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env fish
  2. echo "Setting up ESP-IDF using fish"
  3. set SHELL_RC "$HOME/.config/fish/config.fish"
  4. # Step 1: Check if curl and git are installed
  5. echo "============== Step 1: Checking if dependencies =========================="
  6. if not type -q curl
  7. echo "curl is not installed. Please install curl."
  8. exit 1
  9. end
  10. if not type -q git
  11. echo "git is not installed. Please install git."
  12. exit 1
  13. end
  14. echo "Dependencies for current script are installed."
  15. # Step 2: Fetch the branches from the GitHub API and find the latest stable release branch
  16. echo "============== Step 2: Fetching branch list from ESP-IDF GitHub API =============="
  17. set LATEST_BRANCH (curl -s https://api.github.com/repos/espressif/esp-idf/branches | grep -o '"name": "release/[^"]*' | awk -F'"' '{print $4}' | sort -V | tail -n 1)
  18. # Log the latest branch found
  19. echo "Latest stable branch found: $LATEST_BRANCH"
  20. # Step 3: Clone or update the ESP-IDF repository
  21. if not test -d "$HOME/esp-idf"
  22. echo "============== Step 3: Cloning the ESP-IDF repository ================"
  23. git clone -b "$LATEST_BRANCH" --recursive --depth 1 https://github.com/espressif/esp-idf.git "$HOME/esp-idf"
  24. else
  25. echo "ESP-IDF repository already exists."
  26. cd "$HOME/esp-idf" || exit
  27. git checkout "$LATEST_BRANCH"
  28. git pull --recurse-submodules
  29. end
  30. cd "$HOME/esp-idf" || exit
  31. set IDF_COMMIT (git rev-parse HEAD)
  32. echo "ESP-IDF is set to commit: $IDF_COMMIT"
  33. # Step 4: Set up the ESP-IDF environment
  34. echo "============== Step 4: Setting up the ESP-IDF environment ================"
  35. "$HOME/esp-idf/install.fish"
  36. source "$HOME/esp-idf/export.fish" | source
  37. # Step 5: Add alias to Fish config
  38. echo "============== Step 5: Adding alias to Fish configuration ==============="
  39. if not grep -q "alias get-idf" "$SHELL_RC"
  40. read -P "Do you want to add the alias 'get-idf' to $SHELL_RC? [yes/no] " response
  41. if string match -i -r '^yes$' $response
  42. echo "alias get-idf='source $HOME/esp-idf/export.fish | source'" >> "$SHELL_RC"
  43. echo "ESP-IDF setup alias added to $SHELL_RC. Run 'get-idf' to configure your environment."
  44. else
  45. echo "Alias not added. You can manually add 'alias get-idf=\". $HOME/esp-idf/export.fish | source\"' to $SHELL_RC."
  46. end
  47. else
  48. echo "ESP-IDF setup alias already exists in $SHELL_RC."
  49. end
  50. # Step 6: Inform user to reload shell
  51. echo "============== Step 6: Informing user to reload shell ==============="
  52. echo "Please run 'source $SHELL_RC' to reload the shell with the new alias."
  53. echo "In new shell, run 'get-idf' to enable ESP-IDF environment."