feat: add custom shell command config (#1361)

This commit is contained in:
Peter Cardenas
2025-02-23 05:55:37 -08:00
committed by GitHub
parent e47c27af66
commit 3dd1854cd4
4 changed files with 11 additions and 3 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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)

View File

@@ -1,5 +1,6 @@
local stub = require("luassert.stub")
local LlmTools = require("avante.llm_tools")
local Config = require("avante.config")
local Utils = require("avante.utils")
LlmTools.confirm = function(msg) return true end
@@ -9,6 +10,7 @@ describe("llm_tools", function()
local test_file = test_dir .. "/test.txt"
before_each(function()
Config.setup()
-- 创建测试目录和文件
os.execute("mkdir -p " .. test_dir)
os.execute(string.format("cd %s; git init", test_dir))