Compare commits

...

6 commits

Author SHA1 Message Date
raf
96d0f73eed
Merge pull request #17 from refractalize/refresh-status-after-edit
Some checks failed
Style & Lint / lint (5.1) (push) Has been cancelled
Style & Lint / style (0.19.1) (push) Has been cancelled
refresh status after edit
2026-01-21 14:49:39 +03:00
Tim Macfarlane
111bbd921f refresh status after edit 2026-01-21 09:33:49 +01:00
ac9a7d501f
chore: format with stylua
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ib77f8945f0a21484435db29cf7897a8c6a6a6964
2026-01-20 17:48:35 +03:00
b9c1cac9a5
specify direnv v2.33 requirement
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I070fd364adb5d8c64240d8681d8360916a6a6964
2026-01-20 17:48:31 +03:00
raf
2238a611b9
Merge pull request #16 from refractalize/direnv-export-json
use direnv export json for multiline env vars
2026-01-20 14:05:44 +03:00
Tim Macfarlane
f2533e2d55 use direnv export json for multiline env vars 2026-01-20 10:43:39 +01:00
2 changed files with 49 additions and 27 deletions

View file

@ -1,5 +1,7 @@
# direnv.nvim # direnv.nvim
[direnv]: https://direnv.net/
Dead simple Neovim plugin to add automatic Direnv loading, inspired by Dead simple Neovim plugin to add automatic Direnv loading, inspired by
`direnv.vim` and written in Lua for better performance and maintainability. `direnv.vim` and written in Lua for better performance and maintainability.
@ -15,13 +17,14 @@ Dead simple Neovim plugin to add automatic Direnv loading, inspired by
### 📓 TODO ### 📓 TODO
There are things direnv.nvim can _not_ yet do. Mainly, we would like to `direnv.nvim` is generally feature complete. There are no major planned
integrate Treesitter for **syntax highlighting** similar to direnv.vim. features, and it should be considered stable for the most part. What
Unfortunately there isn't a TS grammar for Direnv, but we can port syntax.vim `direnv.nvim` _cannot_ do yet is **syntax highlighting** similar to `direnv.vim`
from direnv.vim. but this is planned to be remedied through either using Treesitter, or by
porting `direnv.vim`'s syntax.vim.'
Additionally, it might be worth adding an option to allow direnv on, e.g., Feature requests are welcome. Please create an issue to describe the feature
VimEnter if the user has configured to do so. that you would like to see.
## 📦 Installation ## 📦 Installation
@ -31,7 +34,7 @@ You will need to call the setup function to load the plugin.
### Prerequisites ### Prerequisites
- Neovim 0.8.0 or higher - Neovim 0.8.0 or higher
- [direnv](https://direnv.net/) installed and available in your PATH - [direnv] v2.33.0 or later installed and available in your PATH
### Using lazy.nvim ### Using lazy.nvim

View file

@ -164,6 +164,14 @@ M._get_rc_status = function(callback)
local ok, status = pcall(vim.json.decode, obj.stdout) local ok, status = pcall(vim.json.decode, obj.stdout)
if not ok or not status or not status.state then if not ok or not status or not status.state then
vim.schedule(function()
notify(
"Failed to parse direnv status. Your version of direnv may not support JSON output. "
.. "Please ensure you have direnv v2.33.0 or later installed. "
.. "You can verify by running: direnv status --json",
vim.log.levels.ERROR
)
end)
for _, cb in ipairs(pending_callbacks) do for _, cb in ipairs(pending_callbacks) do
cb(nil, nil) cb(nil, nil)
end end
@ -199,6 +207,11 @@ M._get_rc_status = function(callback)
) )
end end
M.refresh_status = function()
cache.status = nil
M._get_rc_status(function() end)
end
--- Initialize direnv for current directory --- Initialize direnv for current directory
--- @param path string Path to .envrc file --- @param path string Path to .envrc file
M._init = function(path) M._init = function(path)
@ -224,13 +237,21 @@ M._init = function(path)
end end
vim.schedule(function() vim.schedule(function()
local env_commands = vim.split(obj.stdout, "\n") local ok, env = pcall(vim.json.decode, obj.stdout)
if #env_commands > 0 then
for _, cmd in ipairs(env_commands) do if not ok or type(env) ~= "table" then
if cmd ~= "" then notify("Failed to parse direnv JSON output", vim.log.levels.ERROR)
pcall(function() return
vim.cmd(cmd) end
end)
for key, value in pairs(env) do
if value == vim.NIL or value == nil then
vim.env[key] = nil
else
if type(value) ~= "string" then
value = tostring(value)
end
vim.env[key] = value
end end
end end
@ -244,12 +265,11 @@ M._init = function(path)
"User", "User",
{ pattern = "DirenvLoaded", modeline = false } { pattern = "DirenvLoaded", modeline = false }
) )
end
end) end)
end end
vim.system( vim.system(
{ M.config.bin, "export", "vim" }, { M.config.bin, "export", "json" },
{ text = true, cwd = cwd }, { text = true, cwd = cwd },
on_exit on_exit
) )
@ -609,7 +629,7 @@ M.setup = function(user_config)
pattern = ".envrc", pattern = ".envrc",
group = group_id, group = group_id,
callback = function() callback = function()
cache.status = nil M.refresh_status()
notify( notify(
".envrc file changed. Run :Direnv allow to activate changes.", ".envrc file changed. Run :Direnv allow to activate changes.",
vim.log.levels.INFO vim.log.levels.INFO
@ -619,8 +639,7 @@ M.setup = function(user_config)
-- Expose a command to refresh the statusline value without triggering reload -- Expose a command to refresh the statusline value without triggering reload
vim.api.nvim_create_user_command("DirenvStatuslineRefresh", function() vim.api.nvim_create_user_command("DirenvStatuslineRefresh", function()
cache.last_check = 0 M.refresh_status()
M._get_rc_status(function() end)
end, {}) end, {})
M._get_rc_status(function() end) M._get_rc_status(function() end)