Skip to content

Commit

Permalink
Merge pull request #98 from hjdivad/copilot/fix-tmux-session
Browse files Browse the repository at this point in the history
Make goto_fzf_tmux_session not error on invalid selection
  • Loading branch information
hjdivad authored Aug 16, 2024
2 parents 1163a46 + 70d880b commit c117d62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/nvim/config/lua/hjdivad_util/tmux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ function M._selection_string_to_pane_info(selection)
return pane_info
end

---@param selected string[]
---@param opts GotoFzfTmuxSessionOptions
function M._fzf_lua_action_default(selected, opts)
if #selected == 0 then
return
end

local pane_info = M._selection_string_to_pane_info(selected[1])
M.goto_tmux_session(pane_info.session_name, pane_info.window_name)

if opts.quit_on_selection then
vim.cmd('quitall')
end
end

---@class GotoFzfTmuxSessionOptions
---@field quit_on_selection boolean | nil
Expand Down Expand Up @@ -136,12 +150,7 @@ function M.goto_fzf_tmux_session(options)
actions = {
---@param selected string[]
['default'] = function (selected, _)
local pane_info = M._selection_string_to_pane_info(selected[1])
M.goto_tmux_session(pane_info.session_name, pane_info.window_name)

if opts.quit_on_selection then
vim.cmd('quitall')
end
M._fzf_lua_action_default(selected, opts)
end
}
})
Expand Down
8 changes: 8 additions & 0 deletions tests/hjdivad_util/tmux_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ describe("tmux", function()
}, tmux.get_tmux_panes({ socket_name = "tmux_spec" }), "get_tmux_panes can read tmux list-panes")
end)
end)

describe("_fzf_lua_action_default", function()
it("exits without errors when selected is empty", function()
assert.has_no.errors(function()
tmux._fzf_lua_action_default({}, {})
end)
end)
end)
end)

0 comments on commit c117d62

Please sign in to comment.