From 2ca006fc97affe237fbbd9b728f2602cf07455e7 Mon Sep 17 00:00:00 2001 From: Rui Marques Date: Mon, 21 Sep 2020 21:31:28 +0200 Subject: [PATCH] feat: Trim cwd from bufname if possible (#104) --- lua/telescope/make_entry.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 4560c0a..3077661 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -181,6 +181,8 @@ end function make_entry.gen_from_buffer(opts) opts = opts or {} + local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd()) + local get_position = function(entry) local tabpage_wins = vim.api.nvim_tabpage_list_wins(0) for k, v in ipairs(tabpage_wins) do @@ -208,6 +210,11 @@ function make_entry.gen_from_buffer(opts) local bufnr_str = tostring(entry) local bufname = vim.api.nvim_buf_get_name(entry) + -- if bufname is inside the cwd, trim that part of the string + if bufname:sub(1, #cwd) == cwd then + bufname = bufname:sub(#cwd + 1, #bufname) + end + local position = get_position(entry) if '' == bufname then