]>
git.rmz.io Git - dotfiles.git/blob - zsh/plugins/virtualenvwrapper/virtualenvwrapper.plugin.zsh
1 wrapsource
=`which virtualenvwrapper.sh`
3 if [[ -f "$wrapsource" ]]; then
6 if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
7 # Automatically activate Git projects' virtual environments based on the
8 # directory name of the project. Virtual environment name can be overridden
9 # by placing a .venv file in the project root with a virtualenv name in it
11 # Check that this is a Git repo
12 PROJECT_ROOT
=`git rev-parse --show-toplevel 2> /dev/null`
13 if (( $?
== 0 )); then
14 # Check for virtualenv name override
15 ENV_NAME
=`basename "$PROJECT_ROOT"`
16 if [[ -f "$PROJECT_ROOT/.venv" ]]; then
17 ENV_NAME
=`cat "$PROJECT_ROOT/.venv"`
19 # Activate the environment only if it is not already active
20 if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
21 if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
22 workon
"$ENV_NAME" && export CD_VIRTUAL_ENV
="$ENV_NAME"
25 elif [ $CD_VIRTUAL_ENV ]; then
26 # We've just left the repo, deactivate the environment
27 # Note: this only happens if the virtualenv was activated automatically
28 deactivate
&& unset CD_VIRTUAL_ENV
33 # New cd function that does the virtualenv magic
35 builtin cd "$@" && workon_cwd
39 print
"zsh virtualenvwrapper plugin: Cannot find virtualenvwrapper.sh. Please install with \`pip install virtualenvwrapper\`."