Skip to content

Commit 1339ffe

Browse files
authored
Merge pull request #159 from mrjones2014/mrj/158/non-zero-exit-code
fix(mux): Change `on_exit` to run on `VimLeavePre` instead of `VimLeave` Also changes to use `jobstart` with `detach = true` for tmux
2 parents e1e1e6c + 89a570a commit 1339ffe

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lua/smart-splits/mux/tmux.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ end
2020

2121
---@param args (string|number)[]
2222
---@param as_list boolean|nil
23-
---@return nil
2423
local function tmux_exec(args, as_list)
2524
local socket = get_socket_path()
2625
if not socket then
@@ -165,10 +164,15 @@ function M.on_exit()
165164
log.warn('tmux init: could not detect pane ID!')
166165
return
167166
end
168-
tmux_exec({ 'set-option', '-pt', pane_id, '@pane-is-vim', 0 })
169-
if vim.v.shell_error ~= 0 then
170-
log.warn('tmux init: failed to detect pane_id')
167+
local socket = get_socket_path()
168+
if not socket then
169+
log.warn('on_exit: Could not find tmux socket')
170+
return
171171
end
172+
local args = { 'set-option', '-pt', pane_id, '@pane-is-vim', 0 }
173+
local cmd = vim.list_extend({ 'tmux', '-S', socket }, args, 1, #args)
174+
175+
vim.fn.jobstart(cmd, { detach = true })
172176
end
173177

174178
return M

lua/smart-splits/mux/utils.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
---Initialization for mux capabilities.
2424
---If selected mux has an `on_init` or `on_exit`,
2525
---call `on_init` and set up autocmds to call `on_init` on `VimResume`
26-
---and `on_exit` on `VimSuspend` and `VimLeave`.
26+
---and `on_exit` on `VimSuspend` and `VimLeavePre`.
2727
function M.startup()
2828
local mux = require('smart-splits.mux').get()
2929
if not mux then
@@ -38,7 +38,7 @@ function M.startup()
3838
})
3939
end
4040
if mux.on_exit then
41-
vim.api.nvim_create_autocmd({ 'VimSuspend', 'VimLeave' }, {
41+
vim.api.nvim_create_autocmd({ 'VimSuspend', 'VimLeavePre' }, {
4242
callback = function()
4343
mux.on_exit()
4444
end,

0 commit comments

Comments
 (0)