From a1ebb36fd183ba24a8dc0d87bf5d8a2faf033064 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Mon, 5 Feb 2024 08:46:47 -0500 Subject: [PATCH] feat: add `wslview` support to `system_open` --- lua/astrocore/init.lua | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/lua/astrocore/init.lua b/lua/astrocore/init.lua index e7e62b6..cb53adc 100644 --- a/lua/astrocore/init.lua +++ b/lua/astrocore/init.lua @@ -109,15 +109,28 @@ function M.system_open(path) -- TODO: remove deprecated method check after dropping support for neovim v0.9 if vim.ui.open then return vim.ui.open(path) end local cmd - if vim.fn.has "win32" == 1 and vim.fn.executable "explorer" == 1 then - cmd = { "cmd.exe", "/K", "explorer" } - elseif vim.fn.has "unix" == 1 and vim.fn.executable "xdg-open" == 1 then - cmd = { "xdg-open" } - elseif (vim.fn.has "mac" == 1 or vim.fn.has "unix" == 1) and vim.fn.executable "open" == 1 then + if vim.fn.has "mac" == 1 then cmd = { "open" } + elseif vim.fn.has "win32" == 1 then + if vim.fn.executable "rundll32" then + cmd = { "rundll32", "url.dll,FileProtocolHandler" } + else + cmd = { "cmd.exe", "/K", "explorer" } + end + elseif vim.fn.has "unix" == 1 then + if vim.fn.executable "wslview" == 1 then + cmd = { "wslview" } + elseif vim.fn.executable "xdg-open" == 1 then + cmd = { "xdg-open" } + end end if not cmd then M.notify("Available system opening tool not found!", vim.log.levels.ERROR) end - vim.fn.jobstart(vim.fn.extend(cmd, { path or vim.fn.expand "" }), { detach = true }) + if not path then + path = vim.fn.expand "" + elseif not path:match "%w+:" then + path = vim.fn.expand(path) + end + vim.fn.jobstart(table.insert(cmd, path), { detach = true }) end --- Toggle a user terminal if it exists, if not then create a new one and save it