diff --git a/lua/fzf-lua/path.lua b/lua/fzf-lua/path.lua index 513b3917..3e8a3b88 100644 --- a/lua/fzf-lua/path.lua +++ b/lua/fzf-lua/path.lua @@ -269,6 +269,12 @@ function M.shorten(path, max_len) local parts = {} local start_idx = 1 max_len = max_len and tonumber(max_len) > 0 and max_len or 1 + if utils.__IS_WINDOWS and M.is_absolute(path) then + -- do not shorten "C:\" to "C", for glob to succeed + -- we need the paths to start with a valid drive spec + table.insert(parts, path:sub(1, 2)) + start_idx = 4 + end repeat local i = find_next_separator(path, start_idx) local end_idx = i and start_idx + math.min(i - start_idx, max_len) - 1 or nil diff --git a/tests/path_spec.lua b/tests/path_spec.lua index a86114a0..14102213 100644 --- a/tests/path_spec.lua +++ b/tests/path_spec.lua @@ -308,11 +308,13 @@ describe("Testing path module", function() assert.are.equal(path.shorten([[/foo/bar]]), [[\f\bar]]) assert.are.equal(path.shorten([[/foo/bar\baz]]), [[\f\b\baz]]) assert.are.equal(path.shorten([[\]]), [[\]]) - assert.are.equal(path.shorten([[c:\foo]]), [[c\foo]]) - assert.are.equal(path.shorten([[c:\foo\bar]]), [[c\f\bar]]) - assert.are.equal(path.shorten([[c:\foo\bar\baz]]), [[c\f\b\baz]]) - assert.are.equal(path.shorten([[c:\.foo\.bar\baz]]), [[c\.f\.b\baz]]) - assert.are.equal(path.shorten([[c:/foo\bar]]), [[c/f/bar]]) + assert.are.equal(path.shorten([[c:/]]), [[c:/]]) + assert.are.equal(path.shorten([[c:\]]), [[c:\]]) + assert.are.equal(path.shorten([[c:\foo]]), [[c:\foo]]) + assert.are.equal(path.shorten([[c:\foo\bar]]), [[c:\f\bar]]) + assert.are.equal(path.shorten([[c:\foo\bar\baz]]), [[c:\f\b\baz]]) + assert.are.equal(path.shorten([[c:\.foo\.bar\baz]]), [[c:\.f\.b\baz]]) + assert.are.equal(path.shorten([[c:/foo\bar]]), [[c:/f/bar]]) assert.are.equal(path.shorten([[~/foo/bar]]), [[~/f/bar]]) assert.are.equal(path.shorten([[~\foo\bar]]), [[~\f\bar]]) assert.are.equal(path.shorten([[~\foo/bar]]), [[~\f\bar]])