1. set ENV_NAME to current folder name instead of an empty string when .venv file is not found
2. optimized activate & deactivated logic
This commit is contained in:
parent
a207a38d63
commit
8f571fe4e5
@ -53,27 +53,26 @@ if [[ ! $DISABLE_VENV_CD -eq 1 ]]; then
|
|||||||
elif [[ "$PROJECT_ROOT" != "." ]]; then
|
elif [[ "$PROJECT_ROOT" != "." ]]; then
|
||||||
ENV_NAME="${PROJECT_ROOT:t}"
|
ENV_NAME="${PROJECT_ROOT:t}"
|
||||||
else
|
else
|
||||||
ENV_NAME=""
|
FOLDER_NAME=`pwd`
|
||||||
|
ENV_NAME=`basename "$FOLDER_NAME"`
|
||||||
fi
|
fi
|
||||||
if [[ "$ENV_NAME" != "" ]]; then
|
# Activate the environment only if it is not already active
|
||||||
# Activate the environment only if it is not already active
|
if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
|
||||||
if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
|
if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
|
||||||
if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
|
workon "$ENV_NAME" && export CD_VIRTUAL_ENV=`pwd`
|
||||||
workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
|
elif [[ -e "$ENV_NAME/bin/activate" ]]; then
|
||||||
elif [[ -e "$ENV_NAME/bin/activate" ]]; then
|
source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV=`pwd`
|
||||||
source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
|
elif [[ `pwd` != "$CD_VIRTUAL_ENV"* ]]; then
|
||||||
fi
|
# We've just left the repo, deactivate the environment
|
||||||
|
# Note: this only happens if the virtualenv was activated automatically
|
||||||
|
deactivate && unset CD_VIRTUAL_ENV
|
||||||
fi
|
fi
|
||||||
elif [[ -n $CD_VIRTUAL_ENV && -n $VIRTUAL_ENV ]]; then
|
|
||||||
# We've just left the repo, deactivate the environment
|
|
||||||
# Note: this only happens if the virtualenv was activated automatically
|
|
||||||
deactivate && unset CD_VIRTUAL_ENV
|
|
||||||
fi
|
fi
|
||||||
unset PROJECT_ROOT
|
unset PROJECT_ROOT
|
||||||
unset WORKON_CWD
|
unset WORKON_CWD
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Append workon_cwd to the chpwd_functions array, so it will be called on cd
|
# Append workon_cwd to the chpwd_functions array, so it will be called on cd
|
||||||
# http://zsh.sourceforge.net/Doc/Release/Functions.html
|
# http://zsh.sourceforge.net/Doc/Release/Functions.html
|
||||||
if ! (( $chpwd_functions[(I)workon_cwd] )); then
|
if ! (( $chpwd_functions[(I)workon_cwd] )); then
|
||||||
|
Loading…
Reference in New Issue
Block a user