viminal2/lua/scripts/autoroot.lua

29 lines
894 B
Lua
Raw Normal View History

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"}
local root_cache = {}
2025-02-01 13:56:22 -08:00
local function set_root()
local path = vim.api.nvim_buf_get_name(0)
2025-02-01 13:56:22 -08:00
if (path == "") then
return
else
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
end
root = vim.fs.dirname(root_file)
root_cache[path] = root
2025-02-01 13:56:22 -08:00
else
end
2025-02-01 13:56:22 -08:00
return vim.fn.chdir(root)
2024-10-10 00:21:39 -07:00
end
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_}