From 679d85c9ffb6bd49d27267b3a282eeb73e063cde Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 30 Dec 2022 20:41:23 +0100 Subject: [PATCH] feat(ui): make brower configurable. Fixes #248 --- README.md | 3 +++ lua/lazy/core/config.lua | 3 +++ lua/lazy/util.lua | 12 +++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f25fcfe..deed95a 100644 --- a/README.md +++ b/README.md @@ -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 custom_keys = { -- you can define custom key maps here. diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index 281086f..87e9c98 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -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 custom_keys = { -- you can define custom key maps here. diff --git a/lua/lazy/util.lua b/lua/lazy/util.lua index fa74b3c..938ede4 100644 --- a/lua/lazy/util.lua +++ b/lua/lazy/util.lua @@ -18,14 +18,20 @@ function M.open(uri) if M.file_exists(uri) then return M.float({ win_opts = { style = "" }, file = uri }) end + local Config = require("lazy.core.config") 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 = { 'cmd.exe', '/c', 'start', '""', uri } elseif vim.fn.has("macunix") == 1 then cmd = { "open", uri } else - cmd = { "xdg-open", uri } + if vim.fn.executable("xdg-open") then + cmd = { "xdg-open", uri } + else + cmd = { "open", uri } + end end local ret = vim.fn.jobstart(cmd, { detach = true })