From 0cd1f554a6686364090b4093d297fa59da01276c Mon Sep 17 00:00:00 2001 From: NicolasGB Date: Sun, 23 Nov 2025 16:43:47 +0100 Subject: [PATCH] fix: Correctly parse complex subcommands and push a table to `terminal.run()` when it's possible instead of making a concat --- lua/jj/cmd/init.lua | 17 ++++++++++++----- lua/jj/ui/terminal.lua | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lua/jj/cmd/init.lua b/lua/jj/cmd/init.lua index 5941dcf..d560e1c 100644 --- a/lua/jj/cmd/init.lua +++ b/lua/jj/cmd/init.lua @@ -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 diff --git a/lua/jj/ui/terminal.lua b/lua/jj/ui/terminal.lua index 7883011..2573775 100644 --- a/lua/jj/ui/terminal.lua +++ b/lua/jj/ui/terminal.lua @@ -328,4 +328,5 @@ function M.run(cmd, keymaps) vim.cmd("stopinsert") end -return M \ No newline at end of file +return M +