From 7d5365ad1463c61936f06ed4eeeefc819e36b3c3 Mon Sep 17 00:00:00 2001 From: Vladimir Shvets Date: Sun, 21 Sep 2025 20:29:53 +0700 Subject: [PATCH] fix(lualine): pretty path fix for mixed case paths on Windows (#4911) ## Description Here's an example of the issue: ```lua local pretty_path = require('lazyvim.util').lualine.pretty_path({ relative = 'cwd' }) -- just a stub local component = { create_hl = function() end, format_hl = function() return '' end, get_default_hl = function() return '' end } local cwd = vim.fn.getcwd() vim.print('cwd: ' .. cwd) vim.print('pretty path: ' .. pretty_path(component)) -- results if `cd d:\tmp` was called previously -- cwd: d:\tmp -- pretty path: d:\tmp\pretty_path_issue.lua -- -- results if `cd D:\tmp` was called previously -- cwd: D:\tmp -- pretty path: pretty_path_issue.lua ``` Depending on the initial path of the `cd` we either get a pretty path or we don't =) I'm not sure if this should be fixed in the neovim itself (considering windows paths as case-insensitive), but I would assume that would take a lot longer to land there, if it's even considered a needed change ## Related Issue(s) Somewhat related to #4763, where I've left a comment, but decided to look a bit deeper ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --- lua/lazyvim/util/lualine.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/util/lualine.lua b/lua/lazyvim/util/lualine.lua index 5f4f1885..a6aa24f3 100644 --- a/lua/lazyvim/util/lualine.lua +++ b/lua/lazyvim/util/lualine.lua @@ -101,9 +101,20 @@ function M.pretty_path(opts) local root = LazyVim.root.get({ normalize = true }) local cwd = LazyVim.root.cwd() - if opts.relative == "cwd" and path:find(cwd, 1, true) == 1 then + -- original path is preserved to provide user with expected result of pretty_path, not a normalized one, + -- which might be confusing + local norm_path = path + + if LazyVim.is_win() then + -- in case any of the provided paths involved mixed case, an additional normalization step for windows + norm_path = norm_path:lower() + root = root:lower() + cwd = cwd:lower() + end + + if opts.relative == "cwd" and norm_path:find(cwd, 1, true) == 1 then path = path:sub(#cwd + 2) - elseif path:find(root, 1, true) == 1 then + elseif norm_path:find(root, 1, true) == 1 then path = path:sub(#root + 2) end