-
Notifications
You must be signed in to change notification settings - Fork 45
/
conda_auto_env.sh
34 lines (31 loc) · 901 Bytes
/
conda_auto_env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# conda-auto-env automatically activates a conda environment when
# entering a folder with an environment.yml file.
#
# If the environment doesn't exist, conda-auto-env creates it and
# activates it for you.
#
# To install add this line to your .bashrc or .bash-profile:
#
# source /path/to/conda_auto_env.sh
#
function conda_auto_env() {
if [ -e "environment.yml" ]; then
# echo "environment.yml file found"
ENV=$(head -n 1 environment.yml | cut -f2 -d ' ')
# Check if you are already in the environment
if [[ $PATH != *$ENV* ]]; then
# Check if the environment exists
source activate $ENV
if [ $? -eq 0 ]; then
:
else
# Create the environment and activate
echo "Conda env '$ENV' doesn't exist."
conda env create -q
source activate $ENV
fi
fi
fi
}
export PROMPT_COMMAND=conda_auto_env