Skip to content

Instantly share code, notes, and snippets.

@simonguest
Created August 14, 2023 17:27
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 simonguest/494f3d48690e7f781917df805e97eceb to your computer and use it in GitHub Desktop.
Save simonguest/494f3d48690e7f781917df805e97eceb to your computer and use it in GitHub Desktop.
Automatic conda activation for VS Code terminal (inc. changing directories)
# 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