Skip to content

Instantly share code, notes, and snippets.

@NZSmartie
Created October 3, 2018 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NZSmartie/caa8cd3500f349df3aa57491c365d76d to your computer and use it in GitHub Desktop.
Save NZSmartie/caa8cd3500f349df3aa57491c365d76d to your computer and use it in GitHub Desktop.
Sets up your IDF_PATH and PATH for use with ESP32 development. also provides `deactivate` function to cleanup
#!/bin/bash
_PRE_IDF_PATH=$PATH
_PRE_IDF_PS1=$PS1
_PWD=$(dirname $(realpath $BASH_SOURCE))
export PATH=$PATH:$_PWD/xtensa-esp32-elf/bin
export IDF_PATH=$_PWD/esp-idf
parse_git_branch () {
git -C $IDF_PATH symbolic-ref HEAD --short 2>/dev/null
}
parse_git_tag () {
git -C $IDF_PATH describe --tags 2> /dev/null
}
parse_git_branch_or_tag() {
local OUT="$(parse_git_branch)"
if [ -z "$OUT" ]; then
OUT="$(parse_git_tag)";
elif [ -z "$OUT" ]; then
OUT="empty"
fi
echo $OUT
}
export PS1="(esp-idf: $(parse_git_branch_or_tag)) "$PS1
deactivate() {
export PATH=$_PRE_IDF_PATH
export PS1=$_PRE_IDF_PS1
unset _PRE_IDF_PATH
unset _PRE_IDF_PS1
unset IDF_PATH
unset -f deactivate # Remove this function
}
unset _PWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment