feat: sessions per branch. Closes #9

This commit is contained in:
Folke Lemaitre 2024-07-06 22:00:20 +02:00
parent 9c0e5227fa
commit cd0054e6a4
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
3 changed files with 17 additions and 1 deletions

View File

@ -35,7 +35,10 @@ Persistence comes with the following defaults:
```lua
{
dir = vim.fn.stdpath("state") .. "/sessions/", -- directory where session files are saved
save_empty = false, -- don't save if there are no open file buffers
-- minimum number of file buffers that need to be open to save
-- Set to 0 to always save
need = 1,
branch = true, -- use git branch to save session
}
```

View File

@ -6,6 +6,7 @@ local defaults = {
-- minimum number of file buffers that need to be open to save
-- Set to 0 to always save
need = 1,
branch = true, -- use git branch to save session
}
---@type Persistence.Config

View File

@ -10,6 +10,12 @@ local e = vim.fn.fnameescape
function M.current()
local name = vim.fn.getcwd():gsub("[\\/:]", "%%")
if Config.options.branch then
local branch = M.branch()
if branch and branch ~= "main" and branch ~= "master" then
name = name .. "-" .. branch
end
end
return Config.options.dir .. name .. ".vim"
end
@ -111,4 +117,10 @@ function M.select()
end)
end
--- get current branch name
---@return string?
function M.branch()
return vim.fn.systemlist("git branch --show-current")[1]
end
return M