Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions lua/persistence/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ function M.last()
return M.list()[1]
end

function M.select()
---@param opts { prompt: string, handler: function}
function M.handle_selected(opts)
---@type { session: string, dir: string, branch?: string }[]
local items = {}
local have = {} ---@type table<string, boolean>
Expand All @@ -122,18 +123,39 @@ function M.select()
end
end
vim.ui.select(items, {
prompt = "Select a session: ",
prompt = opts.prompt,
format_item = function(item)
return vim.fn.fnamemodify(item.dir, ":p:~")
end,
}, function(item)
if item then
vim.fn.chdir(item.dir)
M.load()
opts.handler(item)
end
end)
end

-- select a session to load
function M.select()
M.handle_selected({
prompt = "Select a session: ",
handler = function(item)
vim.fn.chdir(item.dir)
M.load()
end,
})
end

-- select a session to delete
function M.delete()
M.handle_selected({
prompt = "Delete a session: ",
handler = function(item)
os.remove(item.session)
print("Deleted " .. item.session)
end,
})
end

--- get current branch name
---@return string?
function M.branch()
Expand Down
Loading