Skip to content

Commit

Permalink
Merge pull request #159 from mrjones2014/mrj/158/non-zero-exit-code
Browse files Browse the repository at this point in the history
fix(mux): Change `on_exit` to run on `VimLeavePre` instead of `VimLeave`

Also changes to use `jobstart` with `detach = true` for tmux
  • Loading branch information
mrjones2014 authored Mar 1, 2024
2 parents e1e1e6c + 89a570a commit 1339ffe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lua/smart-splits/mux/tmux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions lua/smart-splits/mux/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 1339ffe

Please sign in to comment.