Refactor folders and add metadata table for cached session choices
This commit is contained in:
parent
c4379654bc
commit
c2d4d186fe
5 changed files with 45 additions and 31 deletions
|
|
@ -1,12 +1,13 @@
|
|||
local wezterm = require("wezterm")
|
||||
local State = require("state")
|
||||
local utils = require("utils")
|
||||
local State = require("plugins.sessionizer.state")
|
||||
local utils = require("plugins.sessionizer.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Cache tool availability and scan results
|
||||
local _has_fd = nil
|
||||
local _scan_cache = {}
|
||||
local _meta_lookup = {}
|
||||
|
||||
-- Check for `fd` binary without spawning full shell
|
||||
local function has_fd()
|
||||
|
|
@ -52,7 +53,6 @@ function M.build_cmd(base)
|
|||
return cmd
|
||||
end
|
||||
|
||||
-- Scan the base directory and return a structured list of paths
|
||||
function M.scan_base(base)
|
||||
local key = base.path .. ":" .. (base.max_depth or "default")
|
||||
if _scan_cache[key] then
|
||||
|
|
@ -65,18 +65,30 @@ function M.scan_base(base)
|
|||
return {}
|
||||
end
|
||||
|
||||
local res = {}
|
||||
local choices = {}
|
||||
|
||||
for _, line in ipairs(wezterm.split_by_newlines(out)) do
|
||||
table.insert(res, {
|
||||
id = line,
|
||||
label = line:gsub(wezterm.home_dir, "~"),
|
||||
workspace = utils.basename(line), -- used for workspace naming
|
||||
title = utils.basename(line), -- optional: used for tab titles
|
||||
local id = line
|
||||
local label = line:gsub(wezterm.home_dir, "~")
|
||||
|
||||
table.insert(choices, {
|
||||
id = id,
|
||||
label = label,
|
||||
})
|
||||
|
||||
-- store metadata separately
|
||||
_meta_lookup[id] = {
|
||||
workspace = utils.basename(line),
|
||||
title = utils.basename(line),
|
||||
path = line,
|
||||
}
|
||||
end
|
||||
|
||||
_scan_cache[key] = res
|
||||
return res
|
||||
_scan_cache[key] = choices
|
||||
return choices
|
||||
end
|
||||
|
||||
-- Export metadata so other modules (like ui.lua) can use it
|
||||
M.meta_lookup = _meta_lookup
|
||||
|
||||
return M
|
||||
|
|
|
|||
6
init.lua
6
init.lua
|
|
@ -1,7 +1,7 @@
|
|||
local wezterm = require("wezterm")
|
||||
local state = require("sessionizer.state")
|
||||
local ui = require("sessionizer.ui")
|
||||
local workspaces = require("sessionizer.workspaces")
|
||||
local state = require("plugins.sessionizer.state")
|
||||
local ui = require("plugins.sessionizer.ui")
|
||||
local workspaces = require("plugins.sessionizer.workspaces")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
|
|
|||
28
ui.lua
28
ui.lua
|
|
@ -1,6 +1,7 @@
|
|||
local wezterm = require("wezterm")
|
||||
local act = wezterm.action
|
||||
local workspace = require("workspaces")
|
||||
local command_builder = require("plugins.sessionizer.command_builder")
|
||||
local workspace = require("plugins.sessionizer.workspaces")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
|
@ -15,15 +16,18 @@ local function switch_logic(win, pane, id, label)
|
|||
return
|
||||
end
|
||||
|
||||
-- Expand ~ to home directory reliably
|
||||
local cwd = wezterm.expand_path(id)
|
||||
local metadata = command_builder.meta_lookup[id] or {}
|
||||
|
||||
-- Determine workspace name: use metadata.workspace or fallback to basename of id
|
||||
local workspace_name = metadata.workspace or wezterm.basename(id)
|
||||
local title_label = metadata.title or ("Workspace: " .. label)
|
||||
|
||||
win:perform_action(
|
||||
act.SwitchToWorkspace({
|
||||
name = id, -- use the full path or unique ID as workspace name
|
||||
name = workspace_name, -- Use workspace name from metadata or fallback
|
||||
spawn = {
|
||||
label = "Workspace: " .. label,
|
||||
cwd = cwd,
|
||||
label = title_label, -- Title shown on tab or workspace label
|
||||
cwd = id, -- Start cwd for workspace
|
||||
},
|
||||
}),
|
||||
pane
|
||||
|
|
@ -37,21 +41,19 @@ function M.make_switcher()
|
|||
local choices = workspace.all_dirs()
|
||||
|
||||
if #choices == 0 then
|
||||
-- Notify user visually that no workspaces are available
|
||||
wezterm.toast_notification({
|
||||
title = "Sessionizer",
|
||||
message = "No workspaces found",
|
||||
timeout_milliseconds = 3000,
|
||||
message = "No projects found",
|
||||
timeout_milliseconds = 2000,
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
win:perform_action(
|
||||
act.InputSelector({
|
||||
title = "WezTerm Sessionizer",
|
||||
fuzzy = true, -- Enable fuzzy search
|
||||
-- Case-insensitive search (default is true, but explicit is nice)
|
||||
fuzzy_match_algorithm = "fzy",
|
||||
title = "Sessionizer",
|
||||
fuzzy = true,
|
||||
fuzzy_description = "Fuzzy search projects: ",
|
||||
choices = choices,
|
||||
action = wezterm.action_callback(switch_logic),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
local wezterm = require("wezterm")
|
||||
local State = require("state")
|
||||
local State = require("plugins.sessionizer.state")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
local wezterm = require("wezterm")
|
||||
local state = require("state")
|
||||
local command_builder = require("command_builder")
|
||||
local utils = require("utils")
|
||||
local state = require("plugins.sessionizer.state")
|
||||
local command_builder = require("plugins.sessionizer.command_builder")
|
||||
local utils = require("plugins.sessionizer.utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
Loading…
Reference in a new issue