-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsessions-config.lua
More file actions
43 lines (36 loc) · 1.33 KB
/
Copy pathsessions-config.lua
File metadata and controls
43 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local M = {
'nvim-mini/mini.sessions',
main = 'mini.sessions',
lazy = false,
}
-- NOTE: one global session per directory, same name scheme resession used
local function cwd_session_name()
return (vim.fn.getcwd():gsub('/', '_'):gsub(':', '_'))
end
M.config = function()
local sessions = require('mini.sessions')
sessions.setup {
autoread = false, -- autoread only matches local/latest; cwd-keyed read below
autowrite = true, -- persist on exit only when a session was read/written
directory = vim.fn.stdpath('data') .. '/sessions',
file = '', -- disable local (Session.vim) sessions
}
-- NOTE: load the dir-specific session when opening nvim without file args
vim.api.nvim_create_autocmd('VimEnter', {
callback = function()
local name = cwd_session_name()
if vim.fn.argc(-1) == 0 and MiniSessions.detected[name] then
sessions.read(name)
end
end,
nested = true,
})
end
M.keys = function()
local session_keymap = require('config.keymaps').sessions
return {
{ session_keymap.save, function() require('mini.sessions').write(cwd_session_name()) end },
{ session_keymap.delete, function() require('mini.sessions').delete(cwd_session_name(), { force = true }) end },
}
end
return M