diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 716141664c..b33d9f1e52 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -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 diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index e629eeaecc..ee8d42ab61 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -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", @@ -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) @@ -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,