Last active
December 8, 2016 22:15
-
-
Save kodelint/821a719b9c6e86e41e2eaec0c250341f to your computer and use it in GitHub Desktop.
Auto activate virtualenv
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
auto_activate_virtualenv() { | |
current_dir="${PWD##*/}" | |
if [ -e ~/.virtualenvs/$current_dir ]; then | |
deactivate >/dev/null 2>&1 | |
source ~/.virtualenvs/$current_dir/bin/activate | |
else | |
deactivate >/dev/null 2>&1 | |
fi | |
} | |
pyvenv_cd() { | |
cd "$@" && auto_activate_virtualenv | |
} | |
alias cd="pyvenv_cd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding this to your
.bashrc
or.zshrc
will allow to auto_activate_virtualenv. This could be little heavy as it actually runs the script every time you executecd
. There is a scope of improvement.