Created
January 27, 2015 15:31
-
-
Save sotte/8fb92dff17264c7a2a85 to your computer and use it in GitHub Desktop.
Automatically activate conda environments
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
#!/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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just started using
conda
and wanted similar functionality to other version management tools when traversing directories. This is awesome. Thank you!