From a714522ca946591df86cf80aacbc699edb5ec81a Mon Sep 17 00:00:00 2001 From: Mat Jones Date: Tue, 27 Feb 2024 09:04:33 -0500 Subject: [PATCH 1/2] fix(mux): Change `on_exit` to run on `VimLeavePre` instead of `VimLeave` --- lua/smart-splits/mux/utils.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/smart-splits/mux/utils.lua b/lua/smart-splits/mux/utils.lua index 0712c1c..e02c733 100644 --- a/lua/smart-splits/mux/utils.lua +++ b/lua/smart-splits/mux/utils.lua @@ -23,7 +23,7 @@ end ---Initialization for mux capabilities. ---If selected mux has an `on_init` or `on_exit`, ---call `on_init` and set up autocmds to call `on_init` on `VimResume` ----and `on_exit` on `VimSuspend` and `VimLeave`. +---and `on_exit` on `VimSuspend` and `VimLeavePre`. function M.startup() local mux = require('smart-splits.mux').get() if not mux then @@ -38,7 +38,7 @@ function M.startup() }) end if mux.on_exit then - vim.api.nvim_create_autocmd({ 'VimSuspend', 'VimLeave' }, { + vim.api.nvim_create_autocmd({ 'VimSuspend', 'VimLeavePre' }, { callback = function() mux.on_exit() end, From 89a570a001122983ff86286c03c8a613cc4f6115 Mon Sep 17 00:00:00 2001 From: Mat Jones Date: Wed, 28 Feb 2024 21:46:08 -0500 Subject: [PATCH 2/2] fix: Use jobstart with detach=true --- lua/smart-splits/mux/tmux.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/smart-splits/mux/tmux.lua b/lua/smart-splits/mux/tmux.lua index 5f535cd..4429a78 100644 --- a/lua/smart-splits/mux/tmux.lua +++ b/lua/smart-splits/mux/tmux.lua @@ -20,7 +20,6 @@ end ---@param args (string|number)[] ---@param as_list boolean|nil ----@return nil local function tmux_exec(args, as_list) local socket = get_socket_path() if not socket then @@ -165,10 +164,15 @@ function M.on_exit() log.warn('tmux init: could not detect pane ID!') return end - tmux_exec({ 'set-option', '-pt', pane_id, '@pane-is-vim', 0 }) - if vim.v.shell_error ~= 0 then - log.warn('tmux init: failed to detect pane_id') + local socket = get_socket_path() + if not socket then + log.warn('on_exit: Could not find tmux socket') + return end + local args = { 'set-option', '-pt', pane_id, '@pane-is-vim', 0 } + local cmd = vim.list_extend({ 'tmux', '-S', socket }, args, 1, #args) + + vim.fn.jobstart(cmd, { detach = true }) end return M