Skip to content

Instantly share code, notes, and snippets.

@hantoine
Created December 7, 2020 03:24
Show Gist options
  • Save hantoine/fcdcdc891173761b05e40fcec8e27caf to your computer and use it in GitHub Desktop.
Save hantoine/fcdcdc891173761b05e40fcec8e27caf to your computer and use it in GitHub Desktop.
Automatically activate a conda environment when entering a directory
# The following lines should be added to the file ~/.bashrc
# When the current working directory contains a file named .conda-auto-env, the
# conda environement whose name is the content of the file will be activated
conda-auto-env() {
if [ -e ".conda-auto-env" ] ; then
env=$(cat .conda-auto-env)
if [ "$CONDA_DEFAULT_ENV" != "$env" ] ; then
conda activate $env
fi
fi
}
export PROMPT_COMMAND="conda-auto-env;$PROMPT_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment