make switch function that both ui picker and telescope can use to switch sessions
parent
b8e349c4b2
commit
144e9caf9d
|
|
@ -163,6 +163,26 @@ function M.branch()
|
|||
end
|
||||
end
|
||||
|
||||
-- Switch sessions
|
||||
---@param session_file_path string
|
||||
function M.switch(session_file_path)
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "PersistedSavePost",
|
||||
callback = function()
|
||||
vim.print("delete and load")
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if vim.api.nvim_buf_is_loaded(buf) then
|
||||
vim.api.nvim_buf_delete(buf, {})
|
||||
end
|
||||
end
|
||||
M.load({ session = session_file_path })
|
||||
return true
|
||||
end,
|
||||
})
|
||||
|
||||
M.save({ session = vim.g.persisted_loaded_session })
|
||||
end
|
||||
|
||||
---Select a session to load
|
||||
function M.select()
|
||||
---@type { session: string, dir: string, branch?: string }[]
|
||||
|
|
@ -193,9 +213,7 @@ function M.select()
|
|||
end,
|
||||
}, function(item)
|
||||
if item then
|
||||
-- vim.fn.chdir(item.dir)
|
||||
-- M.load()
|
||||
vim.print(item.session)
|
||||
M.switch(item.session)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,21 +33,22 @@ function M.load_session(session)
|
|||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "PersistedSavePost",
|
||||
callback = function()
|
||||
vim.print("delete and load")
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if vim.api.nvim_buf_is_loaded(buf) then
|
||||
vim.api.nvim_buf_delete(buf, {})
|
||||
end
|
||||
end
|
||||
persisted.load({ session = session.file_path })
|
||||
return true
|
||||
end,
|
||||
})
|
||||
|
||||
persisted.save({ session = vim.g.persisted_loaded_session })
|
||||
-- vim.api.nvim_create_autocmd("User", {
|
||||
-- pattern = "PersistedSavePost",
|
||||
-- callback = function()
|
||||
-- vim.print("delete and load")
|
||||
-- for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
-- if vim.api.nvim_buf_is_loaded(buf) then
|
||||
-- vim.api.nvim_buf_delete(buf, {})
|
||||
-- end
|
||||
-- end
|
||||
-- persisted.load({ session = session.file_path })
|
||||
-- return true
|
||||
-- end,
|
||||
-- })
|
||||
--
|
||||
-- persisted.save({ session = vim.g.persisted_loaded_session })
|
||||
persisted.switch(session.file_path)
|
||||
end
|
||||
|
||||
---Delete the selected session from disk
|
||||
|
|
|
|||
Loading…
Reference in New Issue