Skip to content

Commit

Permalink
Fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeresman01 committed Sep 25, 2024
1 parent 21baa5a commit fbb73ff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lua/tmux-switch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ function M.rename_session()
end)
end

return M
return M
46 changes: 24 additions & 22 deletions lua/tmux-switch/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ local M = {}

--- General function to handle user input for session-related tasks.
--
-- @param prompt_text The text displayed at the top of the input window.
-- @param default_value The default value to display in the input prompt (if any).
-- @param on_submit function Callback function to execute when the input is submitted.
-- @param prompt_text: The text displayed at the top of the input window.
-- @param default_value: The default value to display in the input prompt (if any).
-- @param on_submit: Callback function to execute when the input is submitted.
function M.create_input_prompt(prompt_text, default_value, on_submit)
local input = nui_input({
position = "50%",
Expand Down Expand Up @@ -53,30 +53,32 @@ end
--- Helper function to create and display a tmux session picker.
-- Allows user to select a tmux session from a dropdown menu.
--
-- @param tmux_sessions List of tmux session names to display.
-- @param tmux_sessions: List of tmux session names to display.
function M.show_tmux_session_picker(tmux_sessions)
local opts = themes.get_dropdown({
layout_config = { width = 50 },
})

pickers.new(opts, {
prompt_title = "TMUX switch",

finder = finders.new_table({
results = tmux_sessions,
}),

sorter = sorters.get_generic_fuzzy_sorter(opts),

attach_mappings = function(_, map)
map("i", "<CR>", function(prompt_bufnr)
local selected_session = action_state.get_selected_entry()
actions.close(prompt_bufnr)
util.switch_to_session(selected_session.value)
end)
return true
end,
}):find()
pickers
.new(opts, {
prompt_title = "TMUX switch",

finder = finders.new_table({
results = tmux_sessions,
}),

sorter = sorters.get_generic_fuzzy_sorter(opts),

attach_mappings = function(_, map)
map("i", "<CR>", function(prompt_bufnr)
local selected_session = action_state.get_selected_entry()
actions.close(prompt_bufnr)
util.switch_to_session(selected_session.value)
end)
return true
end,
})
:find()
end

return M
9 changes: 4 additions & 5 deletions lua/tmux-switch/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local M = {}

--- Retrieves a list of tmux session names
--
-- @return a list of tmux session names
-- @return: List of tmux session names
function M.get_tmux_sessions()
local list_tmux_sessions_cmd = "tmux ls | awk -F ':' '{print $1}'"
local handle = io.popen(list_tmux_sessions_cmd)
Expand All @@ -25,7 +25,7 @@ end

--- Switches to a specified tmux session.
--
-- @param session_name The name of the tmux session to switch to.
-- @param session_name: The name of the tmux session to switch to.
function M.switch_to_session(session_name)
if session_name then
local switch_to_session_cmd = string.format("tmux switch -t %s", session_name)
Expand All @@ -45,7 +45,7 @@ end

--- Retrieves the name of the current tmux session.
--
-- @return string|nil The name of the current tmux session, or nil if the session cannot be retrieved.
-- @return string|nil: The name of the current tmux session, or nil if the session cannot be retrieved.
function M.get_current_tmux_session()
local display_current_tmux_session_cmd = "tmux display-message -p '#S'"
local handle = io.popen(display_current_tmux_session_cmd)
Expand All @@ -63,11 +63,10 @@ end

--- Renames the current tmux session.
--
-- @param new_session_name The new name for the current tmux session.
-- @param new_session_name: The new name for the current tmux session.
function M.rename_current_session(new_session_name)
local rename_current_session_cmd = string.format("tmux rename-session %s", new_session_name)
vim.fn.system(rename_current_session_cmd)
end

return M

0 comments on commit fbb73ff

Please sign in to comment.