fix: Correctly parse complex subcommands and push a table to terminal.run() when it's possible instead of making a concat

This commit is contained in:
NicolasGB
2025-11-23 18:07:30 +01:00
committed by Nicolas GB
parent e78c35846a
commit 0cd1f554a6
2 changed files with 14 additions and 6 deletions
+12 -5
View File
@@ -402,6 +402,7 @@ function M.j(args)
return
end
local cmd = nil
if #args == 0 then
local default_cmd_str, success = runner.execute_command(
"jj config get ui.default-command",
@@ -419,16 +420,18 @@ function M.j(args)
terminal.run("jj", M.terminal_keymaps())
return
end
args = default_cmd
cmd = default_cmd
end
if type(args) == "string" then
args = vim.split(args, "%s+")
cmd = vim.split(args, "%s+")
elseif cmd == nil then
-- If a cmd hasn't been parsed make the cmd the whole args
cmd = args
end
local subcommand = args[1]
local remaining_args = vim.list_slice(args, 2)
local cmd = string.format("jj %s", table.concat(args, " "))
local subcommand = cmd[1]
local remaining_args = vim.list_slice(cmd, 2)
local remaining_args_str = table.concat(remaining_args, " ")
local handlers = {
@@ -474,6 +477,10 @@ function M.j(args)
if handlers[subcommand] then
handlers[subcommand]()
else
-- Prepend 'jj' if cmd is an array and doesn't already start with it
if type(cmd) == "table" and cmd[1] ~= "jj" then
table.insert(cmd, 1, "jj")
end
terminal.run(cmd, M.terminal_keymaps())
end
end
+2 -1
View File
@@ -328,4 +328,5 @@ function M.run(cmd, keymaps)
vim.cmd("stopinsert")
end
return M
return M