Skip to content
Closed
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ telescope.setup({opts}) *telescope.setup()*
- "truncate" truncates the start of the path when the whole path will
not fit. To increase the gap between the path and the edge,
set truncate to number `truncate = 3`
- "reverse" reverses the path so that file names are in front

You can also specify the number of characters of each directory name
to keep by setting `path_display.shorten = num`.
Expand All @@ -298,6 +299,18 @@ telescope.setup({opts}) *telescope.setup()*
will give a path like:
`al/beta/gamma/de`


path_display can also be set to 'reverse' string to reverse the path.
The following options can be set to customise the result:

path_display = {
reverse = {
file_sep = " ",
dir_open_sep = "(",
dir_close_sep = ")",
}
},

path_display can also be set to 'hidden' string to hide file names

path_display can also be set to a function for custom formatting of
Expand Down
12 changes: 12 additions & 0 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ append(
- "truncate" truncates the start of the path when the whole path will
not fit. To increase the gap between the path and the edge,
set truncate to number `truncate = 3`
- "reverse" reverses the path so that file names are in front

You can also specify the number of characters of each directory name
to keep by setting `path_display.shorten = num`.
Expand All @@ -327,6 +328,17 @@ append(
will give a path like:
`al/beta/gamma/de`

path_display can also be set to 'reverse' string to reverse the path.
The following options can be set to customise the result:

path_display = {
reverse = {
file_sep = " ",
dir_open_sep = "(",
dir_close_sep = ")",
}
},

path_display can also be set to 'hidden' string to hide file names

path_display can also be set to a function for custom formatting of
Expand Down
36 changes: 36 additions & 0 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ utils.filter_symbols = function(results, opts)
end
end

utils.path_reverse = (function(filepath, file_sep, dir_open_sep, dir_close_sep)
local dirs = vim.split(filepath, "/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't be compatible on Windows with how we currently preserve backslash path separators for Windows.

local reversed_path = ""

for i, dir in ipairs(dirs) do
if 1 == #dirs then
reversed_path = dir .. reversed_path
elseif i == 2 and i == #dirs then
reversed_path = dir .. file_sep .. dir_open_sep .. "/" .. reversed_path .. dir_close_sep
elseif i == 2 then
reversed_path = dir .. "/" .. reversed_path .. dir_close_sep
elseif i == #dirs then
reversed_path = dir .. file_sep .. dir_open_sep .. "/" .. reversed_path
else
reversed_path = dir .. "/" .. reversed_path
end
end

vim.print(reversed_path)

return reversed_path
end)

utils.path_smart = (function()
local paths = {}
return function(filepath)
Expand Down Expand Up @@ -272,6 +295,18 @@ utils.transform_path = function(opts, path)
transformed_path = Path:new(transformed_path):make_relative(cwd)
end

if vim.tbl_contains(path_display, "reverse") or path_display["reverse"] ~= nil then
if type(path_display["reverse"]) == "table" then
local reverse = path_display["reverse"]
transformed_path = utils.path_reverse(transformed_path, reverse.file_sep, reverse.dir_open_sep, reverse.dir_close_sep)
else
local file_sep = ""
local dir_open_sep = ""
local dir_close_sep = ""
transformed_path = utils.path_reverse(transformed_path, file_sep, dir_open_sep, dir_close_sep)
end
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"]
Expand All @@ -280,6 +315,7 @@ utils.transform_path = function(opts, path)
transformed_path = Path:new(transformed_path):shorten(path_display["shorten"])
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)
Expand Down