File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed
Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change 4848-- read_env_file Reads the environment variables found in the `.env` file and
4949-- returns a table with the variables
5050M .read_env_file = function ()
51+
5152 local variables = {}
52- local env_file_path = vim .fn .getcwd () .. " /.env"
53+
54+ -- Directories to search for env files
55+ local env_file_paths = {
56+ -- current working directory
57+ vim .fn .getcwd () .. " /.env" ,
58+ -- directory of the currently opened file
59+ vim .fn .expand (" %:p:h" ) .. " /.env"
60+ }
61+
5362 -- If there's an env file in the current working dir
54- if M .file_exists (env_file_path ) then
55- for line in io.lines (env_file_path ) do
56- local vars = M .split (line , " =" , 1 )
57- variables [vars [1 ]] = vars [2 ]
63+ for _ , env_file_path in ipairs (env_file_paths ) do
64+ if M .file_exists (env_file_path ) then
65+ for line in io.lines (env_file_path ) do
66+ local vars = M .split (line , " =" , 1 )
67+ variables [vars [1 ]] = vars [2 ]
68+ end
5869 end
5970 end
6071
You can’t perform that action at this time.
0 commit comments