diff --git a/lua/opencode/provider/tmux.lua b/lua/opencode/provider/tmux.lua index bf4d443c..1829901a 100644 --- a/lua/opencode/provider/tmux.lua +++ b/lua/opencode/provider/tmux.lua @@ -94,21 +94,27 @@ function Tmux:start() if not pane_id then -- Create new pane local detach_flag = self.opts.focus and "" or "-d" - self.pane_id = vim.fn.system( - string.format("tmux split-window %s -P -F '#{pane_id}' %s '%s'", detach_flag, self.opts.options or "", self.cmd) + self.pane_id = vim.trim( + vim.fn.system( + string.format("tmux split-window %s -P -F '#{pane_id}' %s '%s'", detach_flag, self.opts.options or "", self.cmd) + ) ) local disable_passthrough = self.opts.allow_passthrough ~= true -- default true (disable passthrough) if disable_passthrough and self.pane_id and self.pane_id ~= "" then - vim.fn.system(string.format("tmux set-option -t %s -p allow-passthrough off", vim.trim(self.pane_id))) + vim.fn.system(string.format("tmux set-option -t %s -p allow-passthrough off", self.pane_id)) end end end ----Kill the `opencode` pane. +---Kill the `opencode` pane and its process. function Tmux:stop() local pane_id = self:get_pane_id() if pane_id then + local pid = vim.trim(vim.fn.system("tmux display-message -t " .. pane_id .. " -p '#{pane_pid}'")) vim.fn.system("tmux kill-pane -t " .. pane_id) + if pid ~= "" and tonumber(pid) then + vim.fn.system({ "kill", pid }) + end self.pane_id = nil end end diff --git a/plugin/provider.lua b/plugin/provider.lua index f467ab79..0027805c 100644 --- a/plugin/provider.lua +++ b/plugin/provider.lua @@ -1,4 +1,4 @@ -vim.api.nvim_create_autocmd("VimLeave", { +vim.api.nvim_create_autocmd("VimLeavePre", { group = vim.api.nvim_create_augroup("OpencodeProvider", { clear = true }), pattern = "*", callback = function()