Skip to content

Commit

Permalink
fix(ex.cwd): add separator to the end
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-popov committed Dec 7, 2023
1 parent 5d40b1a commit a497926
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/lualine/components/ex/cwd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Cwd:update_status()
local sep = package.config:sub(1, 1)
local dirs = vim.split(cwd, sep, { plain = true, trimempty = true })
if #dirs <= math.abs(depth) then
return cwd
return cwd:sub(#cwd) == sep and cwd or cwd .. sep
end
local prefix = (self.options.prefix and depth > 0) and self.options.prefix .. sep or ''
local max_length = ex.max_length(self.options.max_length, cwd) or 0
Expand Down
16 changes: 16 additions & 0 deletions tests/components/cwd_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe('cwd component', function()
end)
end)

it('should add the path separator to the end of the cwd', function()
cwd = '/a/b/c'
local opts = { depth = 3 }
l.test_matched_component(component_name, opts, function(ct)
eq(cwd .. '/', ct.value)
end)
end)

it('should contain only {depth} parts of the cwd from the end', function()
cwd = '/a/b/c/d/'
local opts = { depth = 3 }
Expand All @@ -41,6 +49,14 @@ describe('cwd component', function()
end)
end)

it('should add the path separator to the end of the cropped cwd', function()
cwd = '/a/b/c/d'
local opts = { depth = 3 }
l.test_matched_component(component_name, opts, function(ct)
eq('…/b/c/d/', ct.value)
end)
end)

it(
'should contain only {depth} parts of the cwd from the start and do not use prefix',
function()
Expand Down

0 comments on commit a497926

Please sign in to comment.