fix: use vim.ui.open to open uri

fixes #1947
This commit is contained in:
Avinash Thakur 2025-03-14 01:49:54 +05:30
parent 6c3bda4aca
commit c546b12fff
No known key found for this signature in database
GPG key ID: 4877E61DE468FD05

View file

@ -25,30 +25,15 @@ function M.open(uri, opts)
if not opts.system and M.file_exists(uri) then if not opts.system and M.file_exists(uri) then
return M.float({ style = "", file = uri }) return M.float({ style = "", file = uri })
end end
local Config = require("lazy.core.config") local cmd, err = vim.ui.open(uri)
local cmd if cmd then
if not opts.system and Config.options.ui.browser then cmd:wait()
cmd = { Config.options.ui.browser, uri }
elseif vim.fn.has("win32") == 1 then
cmd = { "explorer", uri }
elseif vim.fn.has("macunix") == 1 then
cmd = { "open", uri }
else
if vim.fn.executable("xdg-open") == 1 then
cmd = { "xdg-open", uri }
elseif vim.fn.executable("wslview") == 1 then
cmd = { "wslview", uri }
else
cmd = { "open", uri }
end
end end
if err then
local ret = vim.fn.jobstart(cmd, { detach = true })
if ret <= 0 then
local msg = { local msg = {
"Failed to open uri", "Failed to open uri",
ret, err,
vim.inspect(cmd), vim.inspect(uri),
} }
vim.notify(table.concat(msg, "\n"), vim.log.levels.ERROR) vim.notify(table.concat(msg, "\n"), vim.log.levels.ERROR)
end end