Smart path truncation

This commit is contained in:
Dominik 2026-01-15 02:05:24 +01:00
parent dda59d8a9d
commit a69c70cf65
1 changed files with 31 additions and 0 deletions

View File

@ -38,6 +38,35 @@ M.setup = function()
return '' return ''
end end
local function winbar_path(path, keep)
keep = keep or 3
if path == '' or not path:find('/') then
return path
end
local parts = vim.split(path, '/', { plain = true })
local out = {}
local cutoff = #parts - keep
local truncation_happend = false
for i, part in ipairs(parts) do
if i < cutoff then
truncation_happend = true
else
table.insert(out, part)
end
end
local result = table.concat(out, ' > ')
if truncation_happend then
result = '… > ' .. result
end
return result
end
-- file path -- file path
local filepath = vim.fn.expand('%:~:.') local filepath = vim.fn.expand('%:~:.')
-- override neo-tree default buffer name -- override neo-tree default buffer name
@ -56,6 +85,8 @@ M.setup = function()
local indent = winbar_indent() local indent = winbar_indent()
local icon = winbar_icon(filepath) local icon = winbar_icon(filepath)
filepath = winbar_path(filepath, 3)
if location ~= '' then if location ~= '' then
return indent .. icon .. filepath .. ' > ' .. location return indent .. icon .. filepath .. ' > ' .. location
end end