Skip to content

Commit

Permalink
feat(load): fallback to regular session when branch session does not …
Browse files Browse the repository at this point in the history
…exist (yet)
  • Loading branch information
folke committed Jul 7, 2024
1 parent fc8273b commit a93748a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lua/persistence/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ M._active = false

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("[\\/:]+", "%%")
if Config.options.branch then
if Config.options.branch and opts.branch ~= false then
local branch = M.branch()
if branch and branch ~= "main" and branch ~= "master" then
name = name .. "%%" .. branch:gsub("[\\/:]+", "%%")
Expand Down Expand Up @@ -71,7 +73,16 @@ end
---@param opts? { last?: boolean }
function M.load(opts)
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
M.fire("LoadPre")
vim.cmd("silent! source " .. e(file))
Expand Down

0 comments on commit a93748a

Please sign in to comment.