Skip to content

Commit 0e7302e

Browse files
committed
refactor(nvim)!: determine workspace root & save shadafile to state stdpath
1 parent a53b1e8 commit 0e7302e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Diff for: .config/nvim/init.lua

+22-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,28 @@ opt.sessionoptions = {
8282
'winsize',
8383
'winpos',
8484
}
85-
opt.shadafile = '.vim.shada' -- disable global shada; make jumplist local to project
85+
86+
-- disable global shada; create separate shadafile for each workspace
87+
-- ensures project-scoped jumplist, marks, etc.
88+
--—@return string?
89+
local shadafile = function()
90+
local cwd = vim.uv.cwd()
91+
if not cwd then
92+
return
93+
end
94+
local config = vim.fn.stdpath 'config' --[[@as string]]
95+
local rel_to_config = vim.fs.relpath(config, cwd)
96+
local workspace_root = rel_to_config and config or Snacks.git.get_root(cwd)
97+
if not workspace_root then
98+
return
99+
end
100+
local workspace_uid = vim.fs.basename(workspace_root)
101+
.. '_'
102+
.. vim.fn.sha256(workspace_root):sub(1, 8)
103+
return vim.fn.stdpath 'state' .. '/shada/' .. workspace_uid .. '.shada'
104+
end
105+
vim.o.shadafile = shadafile() or 'NONE'
106+
86107
opt.completeopt = { 'menu', 'menuone', 'noselect' } -- Completion options
87108
opt.clipboard = 'unnamedplus'
88109
opt.inccommand = 'nosplit'

Diff for: .gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# macOS
22
*.DS_Store
33

4-
# Neovim
5-
.vim.shada
6-
74
### Python
85
# Byte-compiled / optimized / DLL files
96
__pycache__/

0 commit comments

Comments
 (0)