diff --git a/README.md b/README.md index 03a14a3..bcb5123 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ ## ⚡️ Requirements -* Neovim >= 0.5.0 +* Neovim >= 0.10.0 * macOS (`open`), Linux (`xdg-open`) or Windows (`powershell.exe start explorer.exe`) ## 📦 Installation @@ -46,6 +46,7 @@ require("lazy").setup({ config = function() require("gx").setup { open_browser_app = "os_specific", -- specify your browser app; default for macOS is "open", Linux "xdg-open" and Windows "powershell.exe" open_browser_args = { "--background" }, -- specify any arguments, such as --background for macOS' "open". + open_browser_options = {}, -- specify options passed to `vim.system`, see `vim.SystemOpts` handlers = { plugin = true, -- open plugin links in lua (e.g. packer, lazy, ..) github = true, -- open github issues diff --git a/lua/gx/git.lua b/lua/gx/git.lua index 7c867a1..98cb031 100644 --- a/lua/gx/git.lua +++ b/lua/gx/git.lua @@ -1,16 +1,17 @@ M = {} local function parse_git_output(result) - if not result or #result < 1 then + if not result or #result < 0 then return end - local domain, repository = result[1]:gsub("%.git%s*$", ""):match("@(.*%..*):(.*)$") + result = vim.trim(result) + local domain, repository = result:gsub("%.git%s*$", ""):match("@(.*%..*):(.*)$") if domain and repository then return "https://" .. domain .. "/" .. repository end - local url = result[1]:gsub("%.git%s*$", ""):match("^https?://.+") + local url = result:gsub("%.git%s*$", ""):match("^https?://.+") if url then return url end diff --git a/lua/gx/init.lua b/lua/gx/init.lua index 12272d4..1f07e67 100644 --- a/lua/gx/init.lua +++ b/lua/gx/init.lua @@ -19,6 +19,7 @@ local M = {} ---@class GxOptions ---@field open_browser_app string ---@field open_browser_args string[] +---@field open_browser_options table ---@field handlers table ---@field handler_options GxHandlerOptions @@ -45,6 +46,7 @@ function M.open(mode, line) return require("gx.shell").execute_with_error( M.options.open_browser_app, M.options.open_browser_args, + M.options.open_browser_options, urls[1].url ) else @@ -61,6 +63,7 @@ function M.open(mode, line) return require("gx.shell").execute_with_error( M.options.open_browser_app, M.options.open_browser_args, + M.options.open_browser_options, selected.url ) end) @@ -97,6 +100,7 @@ local function with_defaults(options) return { open_browser_app = options.open_browser_app or get_open_browser_app(), open_browser_args = options.open_browser_args or get_open_browser_args(), + open_browser_options = {}, handlers = options.handlers or {}, handler_options = { search_engine = options.handler_options.search_engine or "google", diff --git a/lua/gx/shell.lua b/lua/gx/shell.lua index e15a70a..e7deced 100644 --- a/lua/gx/shell.lua +++ b/lua/gx/shell.lua @@ -4,9 +4,10 @@ local shell = {} ---@param command string ---@param args table ---@return integer,table -function shell.execute(command, args) +function shell.execute(command, args, options) if vim.fn.has("nvim-0.10") == 1 then - local result = vim.system({ command, unpack(args) }):wait() + local opts = vim.tbl_extend("force", {}, options) + local result = vim.system({ command, unpack(args) }, opts):wait() return result.code, vim.split(result.stdout, "\n") end @@ -19,14 +20,14 @@ function shell.execute(command, args) return return_val, result end -function shell.execute_with_error(command, args, url) +function shell.execute_with_error(command, args, options, url) local shell_args = {} for _, v in ipairs(args) do table.insert(shell_args, v) end table.insert(shell_args, url) - local return_val, _ = shell.execute(command, shell_args) + local return_val, _ = shell.execute(command, shell_args, options) if return_val ~= 0 then local ret = {}