feat: Add ability to have a user defined function to format the path display (#1000)

This commit is contained in:
Nazeeh ElDirghami
2021-07-16 08:20:25 -07:00
committed by GitHub
parent 37a3a68a78
commit 138697980b
3 changed files with 24 additions and 2 deletions

View File

@@ -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 '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: {} Default: {}
*telescope.defaults.prompt_prefix* *telescope.defaults.prompt_prefix*

View File

@@ -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 '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: {}]] Default: {}]]
}, },

View File

@@ -274,12 +274,16 @@ end
utils.transform_path = function(opts, path) utils.transform_path = function(opts, path)
local path_display = utils.get_default(opts.path_display, require('telescope.config').values.path_display) 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 if utils.is_path_hidden(nil, path_display) then
return '' return ''
end end
local transformed_path = path
if vim.tbl_contains(path_display, "tail") then if vim.tbl_contains(path_display, "tail") then
transformed_path = utils.path_tail(transformed_path) transformed_path = utils.path_tail(transformed_path)
else else