diff --git a/doc/telescope.txt b/doc/telescope.txt index 06815c8..bdd25b3 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -181,6 +181,15 @@ telescope.setup({opts}) *telescope.setup()* 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 + the path display. Example: + + -- Format path as "file.txt (path\to\file\)" + path_display = function(opts, path) + local tail = require("telescope.utils").path_tail(path) + return string.format("%s (%s)", tail, path) + end, + Default: {} *telescope.defaults.prompt_prefix* diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index e5a3ead..d7962c4 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -190,6 +190,15 @@ local telescope_defaults = { 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 + the path display. Example: + + -- Format path as "file.txt (path\to\file\)" + path_display = function(opts, path) + local tail = require("telescope.utils").path_tail(path) + return string.format("%s (%s)", tail, path) + end, + Default: {}]] }, diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 4b2b56b..9238ab7 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -274,12 +274,16 @@ end utils.transform_path = function(opts, path) local path_display = utils.get_default(opts.path_display, require('telescope.config').values.path_display) + local transformed_path = path + + if type(path_display) == "function" then + return path_display(opts, transformed_path) + end + if utils.is_path_hidden(nil, path_display) then return '' end - local transformed_path = path - if vim.tbl_contains(path_display, "tail") then transformed_path = utils.path_tail(transformed_path) else