update OS checks

This commit is contained in:
saeedahsan 2024-03-19 18:11:11 -04:00
parent e09e27b7f0
commit 703f01a3c2

View file

@ -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",