From 703f01a3c2518525d88064e4339e3bffb6599f38 Mon Sep 17 00:00:00 2001 From: saeedahsan Date: Tue, 19 Mar 2024 18:11:11 -0400 Subject: [PATCH] update OS checks --- lua/lazyvim/plugins/editor.lua | 35 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/lua/lazyvim/plugins/editor.lua b/lua/lazyvim/plugins/editor.lua index 5e2c8012..c0c36af8 100644 --- a/lua/lazyvim/plugins/editor.lua +++ b/lua/lazyvim/plugins/editor.lua @@ -71,29 +71,26 @@ return { }, ["O"] = { command = function(state) + local function open_file(filepath) + if vim.fn.has("mac") == 1 then + os.execute("open " .. string.format("'%s'", filepath)) + elseif vim.fn.has("win32") == 1 then + if vim.fn.executable("rundll32") == 1 then + os.execute("rundll32 " .. string.format("'%s'", filepath)) + end + elseif vim.fn.executable("wslview") == 1 then + os.execute("wslview " .. string.format("'%s'", filepath)) + elseif vim.fn.executable("xdg-open") == 1 then + os.execute("xdg-open " .. string.format("'%s'", filepath)) + else + vim.notify("neo-tree: OS not detected", "error") + end + end local filepath = state.tree:get_node().path - if vim.ui.open then vim.ui.open(filepath) - return - end - - 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") + open_file(filepath) end end, desc = "open_with_system_defaults",