diff --git a/README.md b/README.md index 675ee135..05ce50c6 100644 --- a/README.md +++ b/README.md @@ -326,7 +326,9 @@ local defaults = { create = "terminal", ---@type "terminal"|"window"|"split" split = { vertical = true, -- vertical or horizontal split + before = false, -- place the split before the current pane (left when vertical, above when horizontal) size = 0.5, -- size of the split (0-1 for percentage) + close_on_exit = false, -- close the split when Neovim exits }, }, --- Actual cli tool config is loaded from the runtime path `sk/cli/{tool}.lua` and merged with the config below. diff --git a/lua/sidekick/cli/session/tmux.lua b/lua/sidekick/cli/session/tmux.lua index 95dbbb48..d20c5272 100644 --- a/lua/sidekick/cli/session/tmux.lua +++ b/lua/sidekick/cli/session/tmux.lua @@ -44,14 +44,34 @@ function M:start() elseif Config.cli.mux.create == "split" then local cmd = { "tmux", "split-window", "-dP", "-c", self.cwd, "-F", PANE_FORMAT } cmd[#cmd + 1] = Config.cli.mux.split.vertical and "-h" or "-v" + if Config.cli.mux.split.before then + cmd[#cmd + 1] = "-b" + end local size = Config.cli.mux.split.size vim.list_extend(cmd, { "-l", tostring(size <= 1 and ((size * 100) .. "%") or size) }) self:add_cmd(cmd) self:spawn(cmd) + if Config.cli.mux.split.close_on_exit then + self:close_on_exit() + end Util.info(("Started **%s** in a new tmux split"):format(self.tool.name)) end end +--- Kill the tmux pane when Neovim exits. +function M:close_on_exit() + local pane_id = self.tmux_pane_id + if not pane_id then + return + end + vim.api.nvim_create_autocmd("VimLeavePre", { + once = true, + callback = function() + pcall(Util.exec, { "tmux", "kill-pane", "-t", pane_id }, { notify = false }) + end, + }) +end + --- Execute the given tmux command and update the session info, --- based on the first pane returned. ---@param cmd string[] diff --git a/lua/sidekick/config.lua b/lua/sidekick/config.lua index d30e92e8..a6f1bfb7 100644 --- a/lua/sidekick/config.lua +++ b/lua/sidekick/config.lua @@ -93,7 +93,9 @@ local defaults = { create = "terminal", ---@type "terminal"|"window"|"split" split = { vertical = true, -- vertical or horizontal split + before = false, -- place the split before the current pane (left when vertical, above when horizontal) size = 0.5, -- size of the split (0-1 for percentage) + close_on_exit = false, -- close the split when Neovim exits }, -- max lines to capture when dumping a multiplexer pane for scrollback support -- more lines means slower loading of the scrollback