8 Commits

Author SHA1 Message Date
fc8273bac0 chore(main): release 3.0.1 (#63)
🤖 I have created a release *beep* *boop*
---


##
[3.0.1](https://github.com/folke/persistence.nvim/compare/v3.0.0...v3.0.1)
(2024-07-07)


### Bug Fixes

* branch detection. Closes
[#62](https://github.com/folke/persistence.nvim/issues/62)
([a1d37fa](a1d37fa32e))
* **branch:** escape branch name. Fixes
[#65](https://github.com/folke/persistence.nvim/issues/65)
([1565ca0](1565ca0af2))
* windows
([2d83b1a](2d83b1a5c3))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-07-07 09:24:55 +02:00
2d83b1a5c3 fix: windows 2024-07-07 05:36:38 +02:00
f18d0131ed chore(build): auto-generate docs 2024-07-07 05:03:13 +00:00
1565ca0af2 fix(branch): escape branch name. Fixes #65 2024-07-07 07:02:32 +02:00
2c7d3eb6b8 ci: update 2024-07-06 23:45:36 +02:00
a1d37fa32e fix: branch detection. Closes #62 2024-07-06 23:21:20 +02:00
34f337e383 ci: update 2024-07-06 23:19:54 +02:00
8b83876213 ci: update 2024-07-06 23:18:35 +02:00
5 changed files with 43 additions and 25 deletions

View File

@ -12,4 +12,3 @@ jobs:
with:
plugin: persistence.nvim
repo: folke/persistence.nvim
tests: false

11
.gitignore vendored
View File

@ -1,8 +1,9 @@
*.log
.repro
.tests
build
debug
doc/tags
/.repro
/.tests
/build
/debug
/doc/tags
foo.*
node_modules
tt.*

View File

@ -1,5 +1,14 @@
# Changelog
## [3.0.1](https://github.com/folke/persistence.nvim/compare/v3.0.0...v3.0.1) (2024-07-07)
### Bug Fixes
* branch detection. Closes [#62](https://github.com/folke/persistence.nvim/issues/62) ([a1d37fa](https://github.com/folke/persistence.nvim/commit/a1d37fa32ef9431f6a57c217ba5c456d20834679))
* **branch:** escape branch name. Fixes [#65](https://github.com/folke/persistence.nvim/issues/65) ([1565ca0](https://github.com/folke/persistence.nvim/commit/1565ca0af2d93ee94335c2950d92bc133c90aa82))
* windows ([2d83b1a](https://github.com/folke/persistence.nvim/commit/2d83b1a5c3fe5b2251866f5263fb9607db8d64c0))
## [3.0.0](https://github.com/folke/persistence.nvim/compare/v2.0.0...v3.0.0) (2024-07-06)

View File

@ -1,4 +1,4 @@
*persistence.nvim.txt* For Neovim Last change: 2024 July 06
*persistence.nvim.txt* For Neovim Last change: 2024 July 07
==============================================================================
Table of Contents *persistence.nvim-table-of-contents*

View File

@ -3,17 +3,16 @@ local Config = require("persistence.config")
local uv = vim.uv or vim.loop
local M = {}
---@type string?
M._current = nil
M._active = false
local e = vim.fn.fnameescape
function M.current()
local name = vim.fn.getcwd():gsub("[\\/:]", "%%")
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
name = name .. "%%" .. branch:gsub("[\\/:]+", "%%")
end
end
return Config.options.dir .. name .. ".vim"
@ -32,11 +31,11 @@ end
-- Check if a session is active
function M.active()
return M._current ~= nil
return M._active
end
function M.start()
M._current = M.current()
M._active = true
vim.api.nvim_create_autocmd("VimLeavePre", {
group = vim.api.nvim_create_augroup("persistence", { clear = true }),
callback = function()
@ -61,25 +60,22 @@ function M.start()
end
function M.stop()
M._current = nil
M._active = false
pcall(vim.api.nvim_del_augroup_by_name, "persistence")
end
function M.save()
vim.cmd("mks! " .. e(M._current or M.current()))
vim.cmd("mks! " .. e(M.current()))
end
---@param opts? { last?: boolean, file?: string }
---@param opts? { last?: boolean }
function M.load(opts)
opts = opts or {}
local file = opts.file or opts.last and M.last() or M.current()
local file = opts.last and M.last() or M.current()
if file and vim.fn.filereadable(file) ~= 0 then
M.fire("LoadPre")
vim.cmd("silent! source " .. e(file))
M.fire("LoadPost")
if M._current then
M.start()
end
end
end
@ -97,12 +93,21 @@ function M.last()
end
function M.select()
---@type { session: string, dir: string }[]
---@type { session: string, dir: string, branch?: string }[]
local items = {}
local have = {} ---@type table<string, boolean>
for _, session in ipairs(M.list()) do
if uv.fs_stat(session) then
local dir = session:sub(#Config.options.dir + 1, -5):gsub("%%", "/")
items[#items + 1] = { session = session, dir = dir }
local file = session:sub(#Config.options.dir + 1, -5)
local dir, branch = unpack(vim.split(file, "%%", { plain = true }))
dir = dir:gsub("%%", "/")
if jit.os:find("Windows") then
dir = dir:gsub("^(%w)/", "%1:/")
end
if not have[dir] then
have[dir] = true
items[#items + 1] = { session = session, dir = dir, branch = branch }
end
end
end
vim.ui.select(items, {
@ -112,7 +117,8 @@ function M.select()
end,
}, function(item)
if item then
M.load({ file = item.session })
vim.fn.chdir(item.dir)
M.load()
end
end)
end
@ -120,7 +126,10 @@ end
--- get current branch name
---@return string?
function M.branch()
return vim.fn.systemlist("git branch --show-current")[1]
if uv.fs_stat(".git") then
local ret = vim.fn.systemlist("git branch --show-current")[1]
return vim.v.shell_error == 0 and ret or nil
end
end
return M