Enhance bufpath for terminal paths and Windows support

Refactor bufpath function to handle terminal window paths and fix duplicated driver letters on Windows.
This commit is contained in:
ian 2026-03-25 14:33:28 +08:00 committed by GitHub
parent 3f2c1c41e6
commit f054a0240c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,9 +67,13 @@ function M.detectors.pattern(buf, patterns)
end
function M.bufpath(buf)
local path = LazyVim.norm(vim.api.nvim_buf_get_name(assert(buf)))
-- Use pattern to extract path for terminal windows
return M.realpath(path and path:match("^term:/([^:]+)") or path)
local name = LazyVim.norm(vim.api.nvim_buf_get_name(assert(buf)))
local path = name and name:match("^term:/(.+/%d+):") or name
-- fix duplicated driver letters for Windows
if vim.fn.has("win32") == 1 and path and path:find(":/.*:/") then
path = path:gsub("^.-%:/", "", 1)
end
return LazyVim.root.realpath(path)
end
function M.cwd()