Created
September 15, 2022 12:13
-
-
Save larsyencken/c1b2d161e7102e2ad569a735fe088abe to your computer and use it in GitHub Desktop.
zsh: auto-enter python virtualenvs on cd
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
# | |
# python: enter virtualenv on chpwd | |
# | |
load-py-venv() { | |
if [ -f .venv/bin/activate ]; then | |
# enter a virtual environment that's here | |
source .venv/bin/activate | |
elif [ -f env/bin/activate ]; then | |
source env/bin/activate | |
elif [ ! -z "$VIRTUAL_ENV" ] && [ -f pyproject.toml -o -f requirements.txt ]; then | |
# exit a virtual environment when you enter a new project folder | |
deactivate | |
fi | |
} | |
add-zsh-hook chpwd load-py-venv | |
load-py-venv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment