local M = {} local function shell_quote(value) value = tostring(value) return "'" .. value:gsub("'", "'\\''") .. "'" end local function trim(value) return (value or ""):gsub("^%s+", ""):gsub("%s+$", "") end local function run(command) local pipe = io.popen(command .. " 2>/dev/null") if not pipe then return nil end local output = pipe:read("*a") pipe:close() return trim(output) end function M.spawn(...) local args = { ... } if #args == 0 then return end for i, arg in ipairs(args) do args[i] = shell_quote(arg) end local pane_id = run("wezterm cli --prefer-mux spawn -- " .. table.concat(args, " ")) if pane_id and pane_id:match("^%d+$") then hl.exec_cmd("wezterm cli --prefer-mux activate-pane --pane-id " .. shell_quote(pane_id)) end end return M