Skip to content

Commit 9165627

Browse files
committed
feat(nvim): add autocmd to disable shada marks for ignored directory paths
1 parent e0490d5 commit 9165627

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

  • home/dot_config/exact_nvim/exact_lua/exact_user/exact_config/exact_autocmds

home/dot_config/exact_nvim/exact_lua/exact_user/exact_config/exact_autocmds/buffers.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,33 @@ vim.api.nvim_create_autocmd({ 'BufReadPost', 'BufNewFile' }, {
100100
vim.bo.undofile = false
101101
end,
102102
})
103+
104+
---@type string[]
105+
local shada_ignored_dirs = { '.git', 'node_modules' }
106+
107+
vim.api.nvim_create_autocmd({ 'BufReadPost', 'BufNewFile' }, {
108+
group = vim.api.nvim_create_augroup('NoShadaIgnoredDirs', { clear = true }),
109+
pattern = vim.tbl_map(function(dir)
110+
return '*/' .. dir .. '/*'
111+
end, shada_ignored_dirs),
112+
desc = 'Disable shada marks for ignored directory paths.',
113+
---@param args { match: string }
114+
callback = function(args)
115+
---@type string
116+
local path = vim.fs.normalize(args.match)
117+
118+
for _, dir in ipairs(shada_ignored_dirs) do
119+
---@type string?
120+
local prefix = path:match('(.-/' .. vim.pesc(dir) .. '/)')
121+
122+
if prefix and not prefix:find(',', 1, true) then
123+
---@type string
124+
local entry = 'r' .. prefix
125+
126+
if not vim.list_contains(vim.opt.shada:get(), entry) then
127+
vim.opt.shada:append(entry)
128+
end
129+
end
130+
end
131+
end,
132+
})

0 commit comments

Comments
 (0)