Created
August 14, 2023 17:27
-
-
Save simonguest/494f3d48690e7f781917df805e97eceb to your computer and use it in GitHub Desktop.
Automatic conda activation for VS Code terminal (inc. changing directories)
This file contains 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
# conda-autoactivate for VSCode terminal | |
export CONDACONFIGDIR="" | |
if [ -f $PWD/.conda ]; then | |
export CONDACONFIGDIR=$PWD | |
conda activate $(cat .conda) | |
fi | |
# conda-autoactivate when cd into dir | |
cd() { builtin cd "$@" && | |
if [ -f $PWD/.conda ]; then | |
export CONDACONFIGDIR=$PWD | |
conda activate $(cat .conda) | |
elif [ "$CONDACONFIGDIR" ]; then | |
if [[ $PWD != *"$CONDACONFIGDIR"* ]]; then | |
export CONDACONFIGDIR="" | |
conda deactivate | |
fi | |
fi } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment