mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-21 20:11:06 +00:00
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.
This commit is contained in:
parent
13069f2018
commit
7d5365ad14
1 changed files with 13 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue