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
|
||||||
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
|
---Select a session to load
|
||||||
function M.select()
|
function M.select()
|
||||||
---@type { session: string, dir: string, branch?: string }[]
|
---@type { session: string, dir: string, branch?: string }[]
|
||||||
|
|
@ -193,9 +213,7 @@ function M.select()
|
||||||
end,
|
end,
|
||||||
}, function(item)
|
}, function(item)
|
||||||
if item then
|
if item then
|
||||||
-- vim.fn.chdir(item.dir)
|
M.switch(item.session)
|
||||||
-- M.load()
|
|
||||||
vim.print(item.session)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -33,21 +33,22 @@ function M.load_session(session)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("User", {
|
-- vim.api.nvim_create_autocmd("User", {
|
||||||
pattern = "PersistedSavePost",
|
-- pattern = "PersistedSavePost",
|
||||||
callback = function()
|
-- callback = function()
|
||||||
vim.print("delete and load")
|
-- vim.print("delete and load")
|
||||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
-- for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
if vim.api.nvim_buf_is_loaded(buf) then
|
-- if vim.api.nvim_buf_is_loaded(buf) then
|
||||||
vim.api.nvim_buf_delete(buf, {})
|
-- vim.api.nvim_buf_delete(buf, {})
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
persisted.load({ session = session.file_path })
|
-- persisted.load({ session = session.file_path })
|
||||||
return true
|
-- return true
|
||||||
end,
|
-- end,
|
||||||
})
|
-- })
|
||||||
|
--
|
||||||
persisted.save({ session = vim.g.persisted_loaded_session })
|
-- persisted.save({ session = vim.g.persisted_loaded_session })
|
||||||
|
persisted.switch(session.file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Delete the selected session from disk
|
---Delete the selected session from disk
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue