-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
61 lines (55 loc) · 1.49 KB
/
init.lua
File metadata and controls
61 lines (55 loc) · 1.49 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'config.lazy'
local persistenceGroup = vim.api.nvim_create_augroup('Persistence', { clear = true })
local home = vim.fn.expand '~'
local disabled_dirs = {
home,
home .. '/Downloads',
'/tmp',
'/media',
'/mnt',
}
vim.api.nvim_create_autocmd({ 'VimEnter' }, {
group = persistenceGroup,
callback = function()
local cwd = vim.fn.getcwd()
for _, path in pairs(disabled_dirs) do
if path == cwd then
-- exact match
vim.schedule(function()
require('persistence').stop()
end)
return
elseif path ~= home and vim.startswith(cwd, path .. '/') then
-- subdirectory match
vim.schedule(function()
require('persistence').stop()
end)
return
end
end
-- check if nvim was opened with any arguments (files or commands)
local has_file_args = vim.fn.argc() > 0
-- check if nvim was opened with any argv that starts with '+'
local has_ex_commands = false
for i = 2, #vim.v.argv do
if vim.v.argv[i]:match '^%+' then
has_ex_commands = true
break
end
end
if not has_file_args and not has_ex_commands and not vim.g.started_with_stdin then
vim.notify 'Restoring session...'
if vim.bo.filetype == 'lazy' then
vim.cmd 'close'
end
vim.schedule(function()
require('persistence').load()
end)
else
vim.schedule(function()
require('persistence').stop()
end)
end
end,
nested = true,
})