feat: add custom shell command config (#1361)
This commit is contained in:
@@ -388,6 +388,10 @@ M._defaults = {
|
|||||||
--- Disable by setting to -1.
|
--- Disable by setting to -1.
|
||||||
override_timeoutlen = 500,
|
override_timeoutlen = 500,
|
||||||
},
|
},
|
||||||
|
run_command = {
|
||||||
|
-- Only applies to macOS and Linux
|
||||||
|
shell_cmd = "sh -c",
|
||||||
|
},
|
||||||
--- @class AvanteHintsConfig
|
--- @class AvanteHintsConfig
|
||||||
hints = {
|
hints = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ function M.run_command(opts, on_log)
|
|||||||
---change cwd to abs_path
|
---change cwd to abs_path
|
||||||
local old_cwd = vim.fn.getcwd()
|
local old_cwd = vim.fn.getcwd()
|
||||||
vim.fn.chdir(abs_path)
|
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)
|
vim.fn.chdir(old_cwd)
|
||||||
if res.code ~= 0 then
|
if res.code ~= 0 then
|
||||||
if res.stdout then return false, "Error: " .. res.stdout .. "; Error code: " .. tostring(res.code) end
|
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.
|
--- This function will run given shell command synchronously.
|
||||||
---@param input_cmd string
|
---@param input_cmd string
|
||||||
|
---@param shell_cmd string?
|
||||||
---@return vim.SystemCompleted
|
---@return vim.SystemCompleted
|
||||||
M.shell_run = function(input_cmd)
|
M.shell_run = function(input_cmd, shell_cmd)
|
||||||
local shell = vim.o.shell:lower()
|
local shell = vim.o.shell:lower()
|
||||||
---@type string
|
---@type string
|
||||||
local cmd
|
local cmd
|
||||||
@@ -89,7 +90,8 @@ M.shell_run = function(input_cmd)
|
|||||||
cmd = 'powershell.exe -NoProfile -Command "' .. input_cmd:gsub('"', "'") .. '"'
|
cmd = 'powershell.exe -NoProfile -Command "' .. input_cmd:gsub('"', "'") .. '"'
|
||||||
else
|
else
|
||||||
-- linux and macos we wil just do sh -c
|
-- 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
|
end
|
||||||
|
|
||||||
local output = fn.system(cmd)
|
local output = fn.system(cmd)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local stub = require("luassert.stub")
|
local stub = require("luassert.stub")
|
||||||
local LlmTools = require("avante.llm_tools")
|
local LlmTools = require("avante.llm_tools")
|
||||||
|
local Config = require("avante.config")
|
||||||
local Utils = require("avante.utils")
|
local Utils = require("avante.utils")
|
||||||
|
|
||||||
LlmTools.confirm = function(msg) return true end
|
LlmTools.confirm = function(msg) return true end
|
||||||
@@ -9,6 +10,7 @@ describe("llm_tools", function()
|
|||||||
local test_file = test_dir .. "/test.txt"
|
local test_file = test_dir .. "/test.txt"
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
|
Config.setup()
|
||||||
-- 创建测试目录和文件
|
-- 创建测试目录和文件
|
||||||
os.execute("mkdir -p " .. test_dir)
|
os.execute("mkdir -p " .. test_dir)
|
||||||
os.execute(string.format("cd %s; git init", test_dir))
|
os.execute(string.format("cd %s; git init", test_dir))
|
||||||
|
|||||||
Reference in New Issue
Block a user