Created
July 15, 2022 23:12
-
-
Save rmorshea/cd9f28d0b49a8163ff00f7832f9db049 to your computer and use it in GitHub Desktop.
Auto activate venv in current directory
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
#!/bin/bash | |
# activate Python venv in present dir | |
function cd() { | |
if [[ -d ./.venv ]] && [[ $(which python) = $PWD* ]]; then | |
deactivate | |
fi | |
builtin cd $1 | |
if [[ -d ./.venv ]]; then | |
. ./.venv/bin/activate | |
fi | |
} | |
# also activate if the shell was started in a dir with venv | |
if [[ -d ./.venv ]]; then | |
. ./.venv/bin/activate | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment