Commit 110ca86d authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Reinforce Zsh virtualenv-auto plugin against the 'nounset' option

parent 17929187
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
function workon_cwd {
	[[ -n "$DISABLE_WORKON_CWD" ]] && return
	[[ -n "${DISABLE_WORKON_CWD-}" ]] && return
	local DISABLE_WORKON_CWD=1  # recursion protection

	local ENV_ROOT PROJECT_ROOT="${PWD:A}"
	local ENV_ROOT= PROJECT_ROOT="${PWD:A}"
	until [[ "$PROJECT_ROOT" -ef / ]]; do
		[[ -e "$PROJECT_ROOT/.venv" && -z "$ENV_ROOT" ]] &&
			ENV_ROOT="$PROJECT_ROOT/.venv"
@@ -27,11 +27,11 @@ function workon_cwd {

	if [[ -n "$ENV_ROOT" && -f "$ENV_ROOT/bin/activate" ]]; then
		# Activate the environment only if it is not already active
		if [[ ! "$VIRTUAL_ENV" -ef "$ENV_ROOT" ]]; then
		if [[ ! "${VIRTUAL_ENV-}" -ef "$ENV_ROOT" ]]; then
			source "$ENV_ROOT/bin/activate" && export CD_VIRTUAL_ENV="$ENV_ROOT"
		fi
	else
		if [[ -n "$CD_VIRTUAL_ENV" && -n "$VIRTUAL_ENV" ]]; then
		if [[ -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
@@ -41,7 +41,7 @@ function workon_cwd {
}

# 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#Hook-Functions
if ! (( $chpwd_functions[(I)workon_cwd] )); then
	chpwd_functions+=(workon_cwd)
fi