From a69c70cf65e7a54371ea16a76307cd436ef1899b Mon Sep 17 00:00:00 2001 From: Dominik Date: Thu, 15 Jan 2026 02:05:24 +0100 Subject: [PATCH] Smart path truncation --- lua/custom/winbar.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lua/custom/winbar.lua b/lua/custom/winbar.lua index 56dc6c1b..8de9d251 100644 --- a/lua/custom/winbar.lua +++ b/lua/custom/winbar.lua @@ -38,6 +38,35 @@ M.setup = function() return ' ' 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 local filepath = vim.fn.expand('%:~:.') -- override neo-tree default buffer name @@ -56,6 +85,8 @@ M.setup = function() local indent = winbar_indent() local icon = winbar_icon(filepath) + filepath = winbar_path(filepath, 3) + if location ~= '' then return indent .. icon .. filepath .. ' > ' .. location end