2025-02-01 13:56:22 -08:00
|
|
|
-- [nfnl] Compiled from ./fnl/scripts/autoroot.fnl by https://github.com/Olical/nfnl, do not edit.
|
|
|
|
local function _1_()
|
|
|
|
local root_names = {".envrc", ".git", "Makefile", ".svn", ".hg"}
|
2024-10-11 21:08:07 -07:00
|
|
|
local root_cache = {}
|
2025-02-01 13:56:22 -08:00
|
|
|
local function set_root()
|
2024-10-11 21:08:07 -07:00
|
|
|
local path = vim.api.nvim_buf_get_name(0)
|
2025-02-01 13:56:22 -08:00
|
|
|
if (path == "") then
|
|
|
|
return
|
|
|
|
else
|
2024-10-11 21:08:07 -07:00
|
|
|
end
|
|
|
|
path = vim.fs.dirname(path)
|
|
|
|
local root = root_cache[path]
|
2025-02-01 13:56:22 -08:00
|
|
|
if (root == nil) then
|
|
|
|
local root_file = vim.fs.find(root_names, {path = path, upward = true})[1]
|
|
|
|
if (root_file == nil) then
|
|
|
|
return
|
|
|
|
else
|
2024-10-11 21:08:07 -07:00
|
|
|
end
|
|
|
|
root = vim.fs.dirname(root_file)
|
|
|
|
root_cache[path] = root
|
2025-02-01 13:56:22 -08:00
|
|
|
else
|
2024-10-11 21:08:07 -07:00
|
|
|
end
|
2025-02-01 13:56:22 -08:00
|
|
|
return vim.fn.chdir(root)
|
2024-10-10 00:21:39 -07:00
|
|
|
end
|
2024-10-11 21:08:07 -07:00
|
|
|
local root_augroup = vim.api.nvim_create_augroup("MyAutoRoot", {})
|
2025-02-01 13:56:22 -08:00
|
|
|
return vim.api.nvim_create_autocmd("BufEnter", {callback = set_root, group = root_augroup})
|
2024-10-10 00:21:39 -07:00
|
|
|
end
|
2025-02-01 13:56:22 -08:00
|
|
|
return {setup = _1_}
|