Created
February 18, 2021 14:56
-
-
Save keuv-grvl/807ae0609ba9f34ce8503bb1c9a544d0 to your computer and use it in GitHub Desktop.
Autoactivate Conda env when entering a directory (using dir name or provided name).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ln -s /path/to/this/.autoenv.sh /path/to/workdir/ | |
if test -f .autoenv_conda_env_name ; then | |
TARGET_CONDA_ENV="$(cat .autoenv_conda_env_name)" | |
if [[ $TARGET_CONDA_ENV != $CONDA_DEFAULT_ENV ]]; then | |
conda activate "$TARGET_CONDA_ENV" 2&>1 2> /dev/null | |
fi | |
else | |
CUR_DIR=$(basename $(pwd)) | |
conda activate "$CUR_DIR-dev" 2> /dev/null \ | |
|| conda activate "$CUR_DIR-env" 2> /dev/null \ | |
|| echo "❌ no conda env found using names '"$CUR_DIR"[-dev|-env]'.\nWrite the env name to activate to a '.autoenv_conda_env_name' file" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ln -s /path/to/this/.autoenv_leave.sh /path/to/workdir/ | |
if [[ $CONDA_DEFAULT_ENV != "base" ]] ; then | |
conda deactivate | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment