Last active
December 9, 2019 18:03
-
-
Save meetbryce/47821020d1a7dc6838754d1e09dad90b to your computer and use it in GitHub Desktop.
Autoload virtualenv from .venv when moving into a 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
# autoload venv if there's a .venv file | |
# Support for bash | |
PROMPT_COMMAND='prompt' | |
# Mirrored support for zsh. See: https://superuser.com/questions/735660/whats-the-zsh-equivalent-of-bashs-prompt-command/735969#735969 | |
precmd() { eval "$PROMPT_COMMAND" } | |
function prompt() | |
{ | |
if [ "$PWD" != "$MYOLDPWD" ]; then | |
MYOLDPWD="$PWD" | |
test -e .venv && workon `cat .venv` | |
test -e .venv || deactivate &> /dev/null | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment