/
exrc.lua
35 lines (33 loc) · 870 Bytes
/
exrc.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local sourced = {}
vim.api.nvim_create_autocmd("DirChanged", {
desc = "Source .nvim.lua on cd",
group = "StevearcNewConfig",
callback = function(args)
local unsource = {}
for file in pairs(sourced) do
if args.file:sub(1, file:len()) ~= file then
table.insert(unsource, file)
end
end
for _, file in ipairs(unsource) do
local mod = sourced[file]
if type(mod) == "table" and mod.deactivate then
mod.deactivate()
sourced[file] = nil
end
end
local files = vim.fs.find(".nvim.lua", {
upward = true,
path = args.file,
limit = math.huge,
})
for _, file in ipairs(files) do
if not sourced[file] then
local source = vim.secure.read(file)
if source then
sourced[file] = loadstring(source)() or {}
end
end
end
end,
})