Skip to content

Instantly share code, notes, and snippets.

@meetbryce
Last active December 9, 2019 18:03
Show Gist options
  • Save meetbryce/47821020d1a7dc6838754d1e09dad90b to your computer and use it in GitHub Desktop.
Save meetbryce/47821020d1a7dc6838754d1e09dad90b to your computer and use it in GitHub Desktop.
Autoload virtualenv from .venv when moving into a directory
# 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