Last active
July 18, 2018 03:18
-
-
Save floringogianu/c765c8af3ee4d36c5da5edda3d89afcd 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 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
# 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