From 051212f2b15be90fe2226c9c4ae998234cc9a8b8 Mon Sep 17 00:00:00 2001 From: saeedahsan Date: Sun, 17 Mar 2024 18:54:28 -0400 Subject: [PATCH] feat(neo-tree): add OS checks for system default open commands --- lua/lazyvim/plugins/editor.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index e38a1961..79454539 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -72,8 +72,23 @@ return { ["O"] = { command = function(state) local filepath = state.tree:get_node().path - - os.execute("open " .. string.format("'%s'", filepath)) + local uname = vim.loop.os_uname() + local OS = uname.sysname + local is_mac = OS == "Darwin" + local is_linux = OS == "Linux" + local is_windows = OS:find("Windows") and true or false + local is_wsl = is_linux and uname.release:lower():find("microsoft") and true or false + if is_mac then + os.execute("open " .. string.format("'%s'", filepath)) + elseif is_wsl then + os.execute("wslview " .. string.format("'%s'", filepath)) + elseif is_linux then + os.execute("xdg-open " .. string.format("'%s'", filepath)) + elseif is_windows then + os.execute("start " .. string.format("'%s'", filepath)) + else + vim.notify("neo-tree: OS not detected", "error") + end end, desc = "open_with_system_defaults", },