Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
c45ff862b5 | |||
a93748acdb | |||
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:
|
with:
|
||||||
plugin: persistence.nvim
|
plugin: persistence.nvim
|
||||||
repo: folke/persistence.nvim
|
repo: folke/persistence.nvim
|
||||||
tests: false
|
|
||||||
|
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,8 +1,9 @@
|
|||||||
*.log
|
*.log
|
||||||
.repro
|
/.repro
|
||||||
.tests
|
/.tests
|
||||||
build
|
/build
|
||||||
debug
|
/debug
|
||||||
doc/tags
|
/doc/tags
|
||||||
foo.*
|
foo.*
|
||||||
|
node_modules
|
||||||
tt.*
|
tt.*
|
||||||
|
16
CHANGELOG.md
16
CHANGELOG.md
@ -1,5 +1,21 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [3.1.0](https://github.com/folke/persistence.nvim/compare/v3.0.1...v3.1.0) (2024-07-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **load:** fallback to regular session when branch session does not exist (yet) ([a93748a](https://github.com/folke/persistence.nvim/commit/a93748acdb2e7bc4389b3738b4c787b764c3b2a6))
|
||||||
|
|
||||||
|
## [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)
|
## [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*
|
Table of Contents *persistence.nvim-table-of-contents*
|
||||||
|
@ -3,17 +3,18 @@ local Config = require("persistence.config")
|
|||||||
local uv = vim.uv or vim.loop
|
local uv = vim.uv or vim.loop
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
---@type string?
|
M._active = false
|
||||||
M._current = nil
|
|
||||||
|
|
||||||
local e = vim.fn.fnameescape
|
local e = vim.fn.fnameescape
|
||||||
|
|
||||||
function M.current()
|
---@param opts? {branch?: boolean}
|
||||||
local name = vim.fn.getcwd():gsub("[\\/:]", "%%")
|
function M.current(opts)
|
||||||
if Config.options.branch then
|
opts = opts or {}
|
||||||
|
local name = vim.fn.getcwd():gsub("[\\/:]+", "%%")
|
||||||
|
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
|
name = name .. "%%" .. branch:gsub("[\\/:]+", "%%")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return Config.options.dir .. name .. ".vim"
|
return Config.options.dir .. name .. ".vim"
|
||||||
@ -32,11 +33,11 @@ end
|
|||||||
|
|
||||||
-- Check if a session is active
|
-- Check if a session is active
|
||||||
function M.active()
|
function M.active()
|
||||||
return M._current ~= nil
|
return M._active
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.start()
|
function M.start()
|
||||||
M._current = M.current()
|
M._active = true
|
||||||
vim.api.nvim_create_autocmd("VimLeavePre", {
|
vim.api.nvim_create_autocmd("VimLeavePre", {
|
||||||
group = vim.api.nvim_create_augroup("persistence", { clear = true }),
|
group = vim.api.nvim_create_augroup("persistence", { clear = true }),
|
||||||
callback = function()
|
callback = function()
|
||||||
@ -61,25 +62,31 @@ function M.start()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.stop()
|
function M.stop()
|
||||||
M._current = nil
|
M._active = false
|
||||||
pcall(vim.api.nvim_del_augroup_by_name, "persistence")
|
pcall(vim.api.nvim_del_augroup_by_name, "persistence")
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.save()
|
function M.save()
|
||||||
vim.cmd("mks! " .. e(M._current or M.current()))
|
vim.cmd("mks! " .. e(M.current()))
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param opts? { last?: boolean, file?: string }
|
---@param opts? { last?: boolean }
|
||||||
function M.load(opts)
|
function M.load(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
local file = opts.file or 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))
|
||||||
M.fire("LoadPost")
|
M.fire("LoadPost")
|
||||||
if M._current then
|
|
||||||
M.start()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -97,12 +104,21 @@ function M.last()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.select()
|
function M.select()
|
||||||
---@type { session: string, dir: string }[]
|
---@type { session: string, dir: string, branch?: string }[]
|
||||||
local items = {}
|
local items = {}
|
||||||
|
local have = {} ---@type table<string, boolean>
|
||||||
for _, session in ipairs(M.list()) do
|
for _, session in ipairs(M.list()) do
|
||||||
if uv.fs_stat(session) then
|
if uv.fs_stat(session) then
|
||||||
local dir = session:sub(#Config.options.dir + 1, -5):gsub("%%", "/")
|
local file = session:sub(#Config.options.dir + 1, -5)
|
||||||
items[#items + 1] = { session = session, dir = dir }
|
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
|
||||||
end
|
end
|
||||||
vim.ui.select(items, {
|
vim.ui.select(items, {
|
||||||
@ -112,7 +128,8 @@ function M.select()
|
|||||||
end,
|
end,
|
||||||
}, function(item)
|
}, function(item)
|
||||||
if item then
|
if item then
|
||||||
M.load({ file = item.session })
|
vim.fn.chdir(item.dir)
|
||||||
|
M.load()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -120,7 +137,10 @@ end
|
|||||||
--- get current branch name
|
--- get current branch name
|
||||||
---@return string?
|
---@return string?
|
||||||
function M.branch()
|
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
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Reference in New Issue
Block a user