Skip to content

Commit 8cc31a8

Browse files
committed
Environment: find .env in .project & load if found
This builds on the .project file support added in #149, allowing the Environment plugin to search for .project files in virtual environments and to load variables from .env if found in the corresponding project. Fixes #185
1 parent fef43e1 commit 8cc31a8

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

virtualfish/environment.fish

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@ if not set -q VIRTUALFISH_ENVIRONMENT_FILE
44
end
55

66
function __vfsupport_set_env_file_path --description "Set VIRTUALFISH_ENVIRONMENT_FILE_PATH to appropriate value"
7-
set -l vf_path $VIRTUAL_ENV/$VIRTUALFISH_ENVIRONMENT_FILE
7+
set -l project_env_path
8+
set -l venv_env_path $VIRTUAL_ENV/$VIRTUALFISH_ENVIRONMENT_FILE
89
# Check if Projects plugin is used
910
if not set -q PROJECT_HOME
1011
# Always look in the virtualenv dir when not using Projects plugin
11-
echo $vf_path
12+
echo $venv_env_path
1213
else
13-
set -l project_path $PROJECT_HOME/(basename $VIRTUAL_ENV)/$VIRTUALFISH_ENVIRONMENT_FILE
14-
if not test -r $project_path
15-
and test -r $vf_path
16-
# Only use virtualenv dir when there is already a file there
17-
echo $vf_path
14+
# If a .project file exists in virtualenv, look for .env in that project.
15+
if test -r $VIRTUAL_ENV/.project
16+
set project_env_path (command cat $VIRTUAL_ENV/.project)/$VIRTUALFISH_ENVIRONMENT_FILE
17+
# Otherwise assume the project has the same name as current virtualenv
1818
else
19-
# Prefer to use the project dir
20-
echo $project_path
19+
set project_env_path $PROJECT_HOME/(basename $VIRTUAL_ENV)/$VIRTUALFISH_ENVIRONMENT_FILE
20+
end
21+
# If .env is not found in project, fall back to $VIRTUAL_ENV/.env
22+
if not test -r $project_env_path
23+
and test -r $venv_env_path
24+
echo $venv_env_path
25+
else
26+
echo $project_env_path
2127
end
2228
end
2329
end

0 commit comments

Comments
 (0)