Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ directory.

If you are using both the *Compatibility Aliases* and *Projects* plugins,
``workon`` will alias ``vf workon`` instead of ``vf activate``.
If you are using both the *Auto-activation* and *Projects* plugins, the
project's virtual environment will be deactivated automatically when you
leave the project's directory.


Commands
Expand Down
24 changes: 23 additions & 1 deletion virtualfish/auto_activation.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,30 @@ function __vfsupport_auto_activate --on-variable PWD
return
end

# find an auto-activation file
# find an auto-activation file or determine whether inside a project directory
set -l activation_root $PWD
set -l new_virtualenv_name ""

# Projects plugin compatibility: Enable auto-deactivation (1/3)
# Check if active virtualenv (if any) is connected to a project
if test -e "$VIRTUAL_ENV/.project"
set project_path (command cat "$VIRTUAL_ENV/.project")
end

while test $activation_root != ""
if test -f "$activation_root/$VIRTUALFISH_ACTIVATION_FILE"
set new_virtualenv_name (command cat "$activation_root/$VIRTUALFISH_ACTIVATION_FILE")
break

# Projects plugin compatibility: Enable auto-deactivation (2/3)
# vf workon might activate virtualenvs without activation files. To detect those instances
# here in the Auto-activation plugin, check if activation root is a project path. If so,
# set new_virtualenv_name to the basename of the project path
else if test "$project_path" = "$activation_root"
set new_virtualenv_name (command basename $project_path)
break
end

# this strips the last path component from the path.
set activation_root (echo $activation_root | sed 's|/[^/]*$||')
end
Expand All @@ -29,6 +45,12 @@ function __vfsupport_auto_activate --on-variable PWD
# if there's an auto-activated virtualenv, deactivate it
if set -q VIRTUAL_ENV VF_AUTO_ACTIVATED
vf deactivate

# Projects plugin compatibility: Enable auto-deactivation (3/3)
# vf workon doesn't set VF_AUTO_ACTIVATED. To deactivate virtualenv automatically when
# leaving project directory, we check if any virtualenv is active while not in project path
else if begin set -q VIRTUAL_ENV; and test "$project_path" != "$activation_root"; end
vf deactivate
end
end
end
Expand Down