File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed
Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -63,16 +63,21 @@ function M.parse(path, setter)
6363 end
6464 else
6565 -- TODO: rewrite the parser with tree-sitter-bash instead
66- local vars_tbl = vim .split (file_contents , " \n " , { trimempty = true })
67- logger .debug (vars_tbl )
68- for _ , var in ipairs (vars_tbl ) do
69- local variable_name , variable_value = var :match (" ([^#=%s]+)%s*=%s*([^#]*)" )
70- if variable_name then
71- variable_value = variable_value :match (' ^"(.*)"$' ) or variable_value :match (" ^'(.*)'$" ) or variable_value
72- logger .debug (" set " .. variable_name .. " =" .. variable_value )
73- setter (variable_name , value_tostring (variable_value ))
74- end
75- end
66+ local lines = vim .split (file_contents , " \n " , { trimempty = true })
67+ logger .debug (lines )
68+ vim .iter (lines )
69+ :filter (function (line )
70+ return not line :match (" ^%s*#" )
71+ end )
72+ :map (function (line )
73+ return line :match (" ^export%s*(.*)" ) or line
74+ end )
75+ :each (function (line )
76+ local name , value = line :match (" ([^#=%s]+)%s*=%s*(.*)" )
77+ if name then
78+ setter (name , value :match (' ^"([^"]*)"$' ) or value :match (" ^'([^']*)'$" ) or value :match (" ([^%s#]*)" ))
79+ end
80+ end )
7681 end
7782 return true , vars
7883end
You can’t perform that action at this time.
0 commit comments