Skip to content

Instantly share code, notes, and snippets.

@sotte
Created January 27, 2015 15:31
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 sotte/8fb92dff17264c7a2a85 to your computer and use it in GitHub Desktop.
Save sotte/8fb92dff17264c7a2a85 to your computer and use it in GitHub Desktop.
Automatically activate conda environments
#!/bin/bash
# .condaauto.sh automatically activates a conda environment when enterring
# a folder that contains a .condaauto file. The first line in the .condaauto
# file is the name of the conda environment.
#
# To make this work you have to source .condaauto.sh in your bashrc or
# equivalent.
#
# I feel sorry for my bash foo :(
function _conda_auto_activate() {
if [ -e ".condaauto" ]; then
# echo ".condaauto file found"
ENV=$(head -n 1 .condaauto)
# Check to see if already activated to avoid redundant activating
if [[ $PATH == *"$ENV"* ]]; then
echo "Conda env '$ENV' already activated."
else
source activate $ENV
fi
fi
}
function chpwd() {
_conda_auto_activate
}
@bmecham
Copy link

bmecham commented Oct 14, 2022

Just started using conda and wanted similar functionality to other version management tools when traversing directories. This is awesome. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment