Skip to content

Commit

Permalink
feat: use vim.system, add option passed to vim.system
Browse files Browse the repository at this point in the history
  • Loading branch information
TwIStOy committed Jul 17, 2024
1 parent cf6ed6b commit b6d251d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lua/gx/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local M = {}
---@class GxOptions
---@field open_browser_app string
---@field open_browser_args string[]
---@field open_browser_options table
---@field handlers (boolean | GxHandler)[]
---@field handler_options GxHandlerOptions | nil

Expand All @@ -43,6 +44,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 @@ -59,6 +61,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 @@ -94,6 +97,7 @@ local function with_defaults(options)
return {
open_browser_app = options.open_browser_app or get_open_browser_app(),
open_browser_args = get_open_browser_args(options.open_browser_args or {}),
open_browser_options = {},
handlers = options.handlers or {},
handler_options = {
search_engine = options.handler_options.search_engine or "google",
Expand Down
17 changes: 7 additions & 10 deletions lua/gx/shell.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
local shell = {}

function shell.execute(command, args)
-- TODO: This could use vim.system() in 0.10+
local Job = require("plenary.job")
function shell.execute(command, args, options)
local cmd = { command, unpack(args) }
local opts = vim.tbl_extend("force", {}, options)

local result, return_val = Job:new({
command = command,
args = args,
}):sync()
local obj = vim.system(cmd, opts):wait()

return return_val, result
return obj.code, (obj.stdout or "")
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

0 comments on commit b6d251d

Please sign in to comment.