feat: add custom shell command config (#1361)
This commit is contained in:
@@ -388,6 +388,10 @@ M._defaults = {
|
||||
--- Disable by setting to -1.
|
||||
override_timeoutlen = 500,
|
||||
},
|
||||
run_command = {
|
||||
-- Only applies to macOS and Linux
|
||||
shell_cmd = "sh -c",
|
||||
},
|
||||
--- @class AvanteHintsConfig
|
||||
hints = {
|
||||
enabled = true,
|
||||
|
||||
@@ -290,7 +290,7 @@ function M.run_command(opts, on_log)
|
||||
---change cwd to abs_path
|
||||
local old_cwd = vim.fn.getcwd()
|
||||
vim.fn.chdir(abs_path)
|
||||
local res = Utils.shell_run(opts.command)
|
||||
local res = Utils.shell_run(opts.command, Config.run_command.shell_cmd)
|
||||
vim.fn.chdir(old_cwd)
|
||||
if res.code ~= 0 then
|
||||
if res.stdout then return false, "Error: " .. res.stdout .. "; Error code: " .. tostring(res.code) end
|
||||
|
||||
@@ -73,8 +73,9 @@ end
|
||||
|
||||
--- This function will run given shell command synchronously.
|
||||
---@param input_cmd string
|
||||
---@param shell_cmd string?
|
||||
---@return vim.SystemCompleted
|
||||
M.shell_run = function(input_cmd)
|
||||
M.shell_run = function(input_cmd, shell_cmd)
|
||||
local shell = vim.o.shell:lower()
|
||||
---@type string
|
||||
local cmd
|
||||
@@ -89,7 +90,8 @@ M.shell_run = function(input_cmd)
|
||||
cmd = 'powershell.exe -NoProfile -Command "' .. input_cmd:gsub('"', "'") .. '"'
|
||||
else
|
||||
-- linux and macos we wil just do sh -c
|
||||
cmd = "sh -c " .. fn.shellescape(input_cmd)
|
||||
shell_cmd = shell_cmd or "sh -c"
|
||||
cmd = shell_cmd .. " " .. fn.shellescape(input_cmd)
|
||||
end
|
||||
|
||||
local output = fn.system(cmd)
|
||||
|
||||
Reference in New Issue
Block a user