Implement working dir integration with neovim terminal bash cd command

This commit is contained in:
Curt Spark 2024-08-04 21:49:35 +01:00
parent 294d39665f
commit 7b2adb5411
1 changed files with 10 additions and 8 deletions

View File

@ -359,12 +359,14 @@ require("which-key").add ({
}
})
-- See :help terminal-events, we can use this to implement cd commands etc changing the working directory of the nvim host and other terminal app to nvim host ipc.
vim.api.nvim_create_autocmd({ 'TermRequest' }, {
-- sleep 5 && printf "\033]7;file://${PWD}/foo/bar\033\\"
vim.api.nvim_create_autocmd({ 'TermRequest' }, {
desc = 'Handles OSC 7 dir change requests',
callback = function(ev)
local dir = string.gsub(vim.v.termrequest, '\x1b]7;file://[^/]*', '')
print(dir)
if string.sub(vim.v.termrequest, 1, 4) == '\x1b]7;' then
local dir = string.gsub(vim.v.termrequest, '\x1b]7;file://[^/.]*', '')
vim.cmd("cd " .. dir)
end
})
end
})