Forked from floringogianu/conda-env-autodetect.plugin.zsh
Created
June 2, 2018 02:05
-
-
Save appleshan/f35add83b0cff1812b315525a200e7cf to your computer and use it in GitHub Desktop.
zsh plugin for autodetecting conda environments based on a .venv file in your project
This file contains 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
# conda-env-autodetect.plugin.zsh | |
# Copy this file to ~/.oh-my-zsh/plugins/conda-env-autodetect/ | |
# And make sure you have a .venv file with your env's name in your | |
# preject's root folder. | |
_conda_env_auto_activate() { | |
if [ -f ".venv" ]; then | |
# check conda is active | |
env_name=$(cat .venv) | |
is_conda=$(which conda) | |
if [ $is_conda = "conda not found" ]; then | |
echo "Conda not yet in path. Type <cd .> or <source activate $env_name>" | |
return | |
else | |
# activate | |
echo "Activating $env_name conda environment." | |
source activate $env_name | |
fi | |
return | |
else | |
if [[ -z "${CONDA_PREFIX}" ]]; then | |
return | |
else | |
echo "Deactivating $env_name conda environment." | |
source deactivate | |
fi | |
fi | |
} | |
# Activate on shell start. | |
_conda_env_auto_activate | |
# Activate on directory change. | |
# Zsh. Should make this for bash too | |
chpwd_functions=(_conda_env_auto_activate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment