diff options
| author | Elvis Claros Castro <elvis@claros.ar> | 2026-06-27 22:48:15 -0300 |
|---|---|---|
| committer | Elvis Claros Castro <elvis@claros.ar> | 2026-06-27 22:48:15 -0300 |
| commit | a0bd84df02ce235123dfc939327e8bd33dffdd7e (patch) | |
| tree | 3a1f3095863502f01a112275a839d81ce832de1c /lua/config/direnv.lua | |
| parent | 2895ac732dce0eece5ab2586f5d4d76ee0fab710 (diff) | |
| download | nvim-conf-a0bd84df02ce235123dfc939327e8bd33dffdd7e.tar.gz nvim-conf-a0bd84df02ce235123dfc939327e8bd33dffdd7e.zip | |
Remplazando y eliminando plugins a favor de cosas nativas.
Diffstat (limited to 'lua/config/direnv.lua')
| -rw-r--r-- | lua/config/direnv.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lua/config/direnv.lua b/lua/config/direnv.lua new file mode 100644 index 0000000..bc89e33 --- /dev/null +++ b/lua/config/direnv.lua @@ -0,0 +1,62 @@ +-- Integración nativa con direnv (reemplaza direnv/direnv.vim) +-- `direnv export json` emite el diff de variables a aplicar para el cwd actual; +-- las variables a eliminar llegan como null (vim.NIL). +local M = {} + +local function apply(env) + if type(env) ~= "table" then + return + end + for k, v in pairs(env) do + if v == vim.NIL then + vim.env[k] = nil + else + vim.env[k] = v + end + end +end + +local function load(sync) + if vim.fn.executable("direnv") == 0 then + return + end + if sync then + -- Carga inicial sincrónica: el entorno debe estar listo antes de los LSP. + local out = vim.fn.system({ "direnv", "export", "json" }) + if vim.v.shell_error ~= 0 or vim.trim(out) == "" then + return + end + local ok, env = pcall(vim.json.decode, out) + if ok then + apply(env) + end + else + vim.system({ "direnv", "export", "json" }, { text = true }, function(obj) + if obj.code ~= 0 then + return + end + local out = vim.trim(obj.stdout or "") + if out == "" then + return + end + local ok, env = pcall(vim.json.decode, out) + if ok then + vim.schedule(function() + apply(env) + end) + end + end) + end +end + +function M.setup() + vim.api.nvim_create_autocmd("DirChanged", { + group = vim.api.nvim_create_augroup("direnv", { clear = true }), + callback = function() + load(false) + end, + }) + load(true) +end + +return M |