Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,28 @@ utils.transform_path = function(opts, path)
transformed_path = Path:new(transformed_path):make_relative(cwd)
end

if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then
if type(path_display["shorten"]) == "table" then
local shorten = path_display["shorten"]
transformed_path = Path:new(transformed_path):shorten(shorten.len, shorten.exclude)
else
local length = type(path_display["shorten"]) == "number" and path_display["shorten"]
transformed_path = Path:new(transformed_path):shorten(length)
end
end

if vim.tbl_contains(path_display, "truncate") or path_display.truncate then
if opts.__length == nil then
opts.__length = calc_result_length(path_display.truncate)
end
if opts.__prefix == nil then
opts.__prefix = 0
end
transformed_path = truncate(transformed_path, opts.__length - opts.__prefix, nil, -1)
end

-- IMPORTANT: filename_first needs to be the last option. Otherwise the
-- other options will not be displayed correctly.
if vim.tbl_contains(path_display, "filename_first") or path_display["filename_first"] ~= nil then
local reverse_directories = false

Expand Down Expand Up @@ -337,26 +359,6 @@ utils.transform_path = function(opts, path)

path_style = { { { #filename, #transformed_path }, "TelescopeResultsComment" } }
end

if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then
if type(path_display["shorten"]) == "table" then
local shorten = path_display["shorten"]
transformed_path = Path:new(transformed_path):shorten(shorten.len, shorten.exclude)
else
local length = type(path_display["shorten"]) == "number" and path_display["shorten"]
transformed_path = Path:new(transformed_path):shorten(length)
end
end

if vim.tbl_contains(path_display, "truncate") or path_display.truncate then
if opts.__length == nil then
opts.__length = calc_result_length(path_display.truncate)
end
if opts.__prefix == nil then
opts.__prefix = 0
end
transformed_path = truncate(transformed_path, opts.__length - opts.__prefix, nil, -1)
end
end

return transformed_path, path_style
Expand Down