Feat(osc7): cwd tracking and matching

Writes the CWD to a file (and emits the OSC7) at startup and when the directory changes. This is
used by a function in fish-shell to automatically cd to the cwd on nvim exit.
This commit is contained in:
2025-03-18 22:26:49 -04:00
parent 0ae80edfff
commit c4aa09b6be
+36
View File
@@ -128,4 +128,40 @@ autocmd({ 'BufEnter' }, {
end,
})
-- Update OSC7 in fish shell
local function update_osc7()
local cwd = vim.fn.getcwd()
local uri = 'file://' .. vim.fn.hostname() .. cwd
io.stdout:write('\27]7;' .. uri .. '\27\\')
end
-- Save CWD where we can access it
local function save_cwd()
local cwd = vim.fn.getcwd()
local file = io.open(os.getenv('HOME') .. '/.nvim_last_dir', 'w')
if file then
file:write(cwd)
file:close()
end
end
-- Update OSC7 and file on directory change
autocmd('DirChanged', {
callback = function()
save_cwd()
update_osc7()
end,
})
-- Save on exit
autocmd('VimLeavePre', {
callback = save_cwd,
})
-- Send OSC 7 on startup
update_osc7()
-- Save CWD on startup
save_cwd()
return M