Created
April 15, 2012 23:02
-
-
Save mattjmorrison/2395220 to your computer and use it in GitHub Desktop.
@toranb's Automatically 'workon' a 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
# This makes 3 assumptions | |
# 1.) the root project directory must have a .git file (this way it won't try to "workon" in every single | |
# directory on your machine) | |
# 2.) the virtualenv name for your project must match the root directory name of your project | |
# 3.) you want it to auto switch virtualenvs for you when you jump between different project directories | |
# (when you hit another dir w/ a virtualenv that is) | |
workon_virtualenv() { | |
if [ -e .git ]; then | |
current_dir="${PWD##*/}" | |
if [ -e ~/virtualenvs/$current_dir ]; then | |
deactivate >/dev/null 2>&1 | |
source ~/virtualenvs/$current_dir/bin/activate | |
fi | |
fi | |
} | |
virtualenv_cd() { | |
cd "$@" && workon_virtualenv | |
} | |
alias cd="virtualenv_cd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great! A small suggestion: why not using
$WORKON_HOME
instead of hardcoding~/virtualenvs/
as the directory containing virtualenvs?