feat(ui): make brower configurable. Fixes #248

This commit is contained in:
Folke Lemaitre 2022-12-30 20:41:23 +01:00
parent 730bb84364
commit 679d85c9ff
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 15 additions and 3 deletions

View File

@ -345,6 +345,9 @@ return {
"", "",
}, },
}, },
-- leave nil, to automatically select a browser depending on your OS.
-- If you want to use a specific browser, you can define it here
browser = nil, ---@type string?
throttle = 20, -- how frequently should the ui process render events throttle = 20, -- how frequently should the ui process render events
custom_keys = { custom_keys = {
-- you can define custom key maps here. -- you can define custom key maps here.

View File

@ -59,6 +59,9 @@ M.defaults = {
"", "",
}, },
}, },
-- leave nil, to automatically select a browser depending on your OS.
-- If you want to use a specific browser, you can define it here
browser = nil, ---@type string?
throttle = 20, -- how frequently should the ui process render events throttle = 20, -- how frequently should the ui process render events
custom_keys = { custom_keys = {
-- you can define custom key maps here. -- you can define custom key maps here.

View File

@ -18,14 +18,20 @@ function M.open(uri)
if M.file_exists(uri) then if M.file_exists(uri) then
return M.float({ win_opts = { style = "" }, file = uri }) return M.float({ win_opts = { style = "" }, file = uri })
end end
local Config = require("lazy.core.config")
local cmd local cmd
if vim.fn.has("win32") == 1 then if Config.options.ui.browser then
cmd = { Config.options.ui.browser, uri }
elseif vim.fn.has("win32") == 1 then
cmd = { "explorer", uri } cmd = { "explorer", uri }
-- cmd = { 'cmd.exe', '/c', 'start', '""', uri }
elseif vim.fn.has("macunix") == 1 then elseif vim.fn.has("macunix") == 1 then
cmd = { "open", uri } cmd = { "open", uri }
else else
if vim.fn.executable("xdg-open") then
cmd = { "xdg-open", uri } cmd = { "xdg-open", uri }
else
cmd = { "open", uri }
end
end end
local ret = vim.fn.jobstart(cmd, { detach = true }) local ret = vim.fn.jobstart(cmd, { detach = true })