Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lua/gx/git.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions lua/gx/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, boolean|GxHandler>
---@field handler_options GxHandlerOptions

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions lua/gx/shell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = {}
Expand Down
Loading