mirror of
https://github.com/folke/persistence.nvim.git
synced 2025-07-16 12:24:41 +02:00
feat(load): fallback to regular session when branch session does not exist (yet)
This commit is contained in:
parent
fc8273bac0
commit
a93748acdb
1 changed files with 14 additions and 3 deletions
|
@ -7,9 +7,11 @@ M._active = false
|
||||||
|
|
||||||
local e = vim.fn.fnameescape
|
local e = vim.fn.fnameescape
|
||||||
|
|
||||||
function M.current()
|
---@param opts? {branch?: boolean}
|
||||||
|
function M.current(opts)
|
||||||
|
opts = opts or {}
|
||||||
local name = vim.fn.getcwd():gsub("[\\/:]+", "%%")
|
local name = vim.fn.getcwd():gsub("[\\/:]+", "%%")
|
||||||
if Config.options.branch then
|
if Config.options.branch and opts.branch ~= false then
|
||||||
local branch = M.branch()
|
local branch = M.branch()
|
||||||
if branch and branch ~= "main" and branch ~= "master" then
|
if branch and branch ~= "main" and branch ~= "master" then
|
||||||
name = name .. "%%" .. branch:gsub("[\\/:]+", "%%")
|
name = name .. "%%" .. branch:gsub("[\\/:]+", "%%")
|
||||||
|
@ -71,7 +73,16 @@ end
|
||||||
---@param opts? { last?: boolean }
|
---@param opts? { last?: boolean }
|
||||||
function M.load(opts)
|
function M.load(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local file = opts.last and M.last() or M.current()
|
---@type string
|
||||||
|
local file
|
||||||
|
if opts.last then
|
||||||
|
file = M.last()
|
||||||
|
else
|
||||||
|
file = M.current()
|
||||||
|
if vim.fn.filereadable(file) == 0 then
|
||||||
|
file = M.current({ branch = false })
|
||||||
|
end
|
||||||
|
end
|
||||||
if file and vim.fn.filereadable(file) ~= 0 then
|
if file and vim.fn.filereadable(file) ~= 0 then
|
||||||
M.fire("LoadPre")
|
M.fire("LoadPre")
|
||||||
vim.cmd("silent! source " .. e(file))
|
vim.cmd("silent! source " .. e(file))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue