Skip to content

Commit

Permalink
feat: add wslview support to system_open
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Feb 5, 2024
1 parent 2aa2ef7 commit a1ebb36
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lua/astrocore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<cfile>" }), { detach = true })
if not path then
path = vim.fn.expand "<cfile>"
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
Expand Down

0 comments on commit a1ebb36

Please sign in to comment.