Skip to content

Commit

Permalink
Restructure the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeresman01 committed Sep 26, 2024
1 parent fbb73ff commit c12bae7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
26 changes: 26 additions & 0 deletions lua/tmux-switch/commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local tmux = require("tmux-switch.tmux")

local M = {}

-- Function that registers all the commands exposed to Neovim
function M.register()
vim.api.nvim_create_user_command("TmuxSwitch", function()
tmux.switch()
end, {
desc = "Run Java test picker",
})

vim.api.nvim_create_user_command("TmuxCreateSession", function()
tmux.create_session()
end, {
desc = "Execute test at cursor position",
})

vim.api.nvim_create_user_command("TmuxRenameSession", function()
tmux.rename_session()
end, {
desc = "Run all tests in the current Java class",
})
end

return M
24 changes: 3 additions & 21 deletions lua/tmux-switch/init.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
local util = require("tmux-switch.ui")
local commands = require("tmux-switch.commands")

local M = {}

--- Switch to an existing tmux session using a picker menu.
function M.switch()
local tmux_sessions = util.get_tmux_sessions()
ui.show_tmux_session_picker(tmux_sessions)
end

--- Create a new tmux session and switch to it.
function M.create_session()
ui.create_input_prompt("[ TMUX switch ]", "", function(session_name)
util.create_new_session(session_name)
util.switch_to_session(session_name)
end)
end

--- Rename the current tmux session.
function M.rename_session()
local current_session = util.get_current_tmux_session()
ui.create_input_prompt("[ TMUX switch ]", current_session, function(new_session_name)
util.rename_current_session(new_session_name)
end)
function M.setup()
commands.register()
end

return M
27 changes: 27 additions & 0 deletions lua/tmux-switch/tmux.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local util = require("tmux-switch.ui")

local M = {}

--- Switch to an existing tmux session using a picker menu.
function M.switch()
local tmux_sessions = util.get_tmux_sessions()
ui.show_tmux_session_picker(tmux_sessions)
end

--- Create a new tmux session and switch to it.
function M.create_session()
ui.create_input_prompt("[ TMUX switch ]", "", function(session_name)
util.create_new_session(session_name)
util.switch_to_session(session_name)
end)
end

--- Rename the current tmux session.
function M.rename_session()
local current_session = util.get_current_tmux_session()
ui.create_input_prompt("[ TMUX switch ]", current_session, function(new_session_name)
util.rename_current_session(new_session_name)
end)
end

return M

0 comments on commit c12bae7

Please sign in to comment.