Skip to content
Open
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 lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,19 @@ append(
Default: require("telescope.previewers").buffer_previewer_maker]]
)

append(
"strip_path_prefix",
nil,
[[
String that will be stripped from the beginning of file paths.
This is useful when running in containers where file paths start
with a specific prefix that you want to remove for better display.

Example: "/app/"

Default: nil]]
)

-- @param user_defaults table: a table where keys are the names of options,
-- and values are the ones the user wants
-- @param tele_defaults table: (optional) a table containing all of the defaults
Expand Down
5 changes: 5 additions & 0 deletions lua/telescope/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local entry_display = require "telescope.pickers.entry_display"
local utils = require "telescope.utils"
local strings = require "plenary.strings"
local Path = require "plenary.path"
local config = require "telescope.config"

local treesitter_type_highlight = {
["associated"] = "TSConstant",
Expand Down Expand Up @@ -454,6 +455,7 @@ end
function make_entry.gen_from_quickfix(opts)
opts = opts or {}
local show_line = vim.F.if_nil(opts.show_line, true)
local strip_prefix = vim.F.if_nil(opts.strip_path_prefix, config.values.strip_path_prefix)

local hidden = utils.is_path_hidden(opts)

Expand All @@ -479,6 +481,9 @@ function make_entry.gen_from_quickfix(opts)
local get_filename = get_filename_fn()
return function(entry)
local filename = vim.F.if_nil(entry.filename, get_filename(entry.bufnr))
if filename and strip_prefix and filename:match("^" .. vim.pesc(strip_prefix)) then
filename = filename:gsub("^" .. vim.pesc(strip_prefix), "")
end

return make_entry.set_default_entry_mt({
value = entry,
Expand Down