exrc.lua 657 B

12345678910111213141516171819202122232425
  1. -- exrc does not work when using -u. Also, unlike exrc, we only evaluate
  2. -- .nvim.lua and only the one in the project root.
  3. local dirs = vim.fs.find({ '.git' }, {
  4. type = 'directory',
  5. upward = true,
  6. stop = vim.env.HOME,
  7. })
  8. if #dirs == 1 then
  9. local file = vim.fs.joinpath(vim.fs.dirname(dirs[1]), '.nvim.lua')
  10. local stat = vim.uv.fs_stat(file)
  11. if stat and stat.type == 'file' then
  12. local trusted = vim.secure.read(file)
  13. if trusted then
  14. assert(loadstring(trusted, '@' .. file))()
  15. end
  16. end
  17. end
  18. -- automatically trust configs we save
  19. vim.api.nvim_create_autocmd('BufWritePost', {
  20. pattern = '.nvim.lua',
  21. command = 'trust',
  22. })