Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
fc8273bac0 | |||
2d83b1a5c3 | |||
f18d0131ed | |||
1565ca0af2 | |||
2c7d3eb6b8 | |||
a1d37fa32e | |||
34f337e383 | |||
8b83876213 |
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -12,4 +12,3 @@ jobs:
|
||||
with:
|
||||
plugin: persistence.nvim
|
||||
repo: folke/persistence.nvim
|
||||
tests: false
|
||||
|
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,8 +1,9 @@
|
||||
*.log
|
||||
.repro
|
||||
.tests
|
||||
build
|
||||
debug
|
||||
doc/tags
|
||||
/.repro
|
||||
/.tests
|
||||
/build
|
||||
/debug
|
||||
/doc/tags
|
||||
foo.*
|
||||
node_modules
|
||||
tt.*
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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*
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user