Skip to content

Commit

Permalink
feat: Add ability to have a user defined function to format the path …
Browse files Browse the repository at this point in the history
…display (#1000)
  • Loading branch information
Nazeehe authored Jul 16, 2021
1 parent 37a3a68 commit 1386979
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
9 changes: 9 additions & 0 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}]]
},

Expand Down
8 changes: 6 additions & 2 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1386979

Please sign in to comment.