diff --git a/.config/nvim/lua/embedded-plugins/my-telescope-searches/lua/my-telescope-searches/init.lua b/.config/nvim/lua/embedded-plugins/my-telescope-searches/lua/my-telescope-searches/init.lua index 014924dd..3c823b9d 100644 --- a/.config/nvim/lua/embedded-plugins/my-telescope-searches/lua/my-telescope-searches/init.lua +++ b/.config/nvim/lua/embedded-plugins/my-telescope-searches/lua/my-telescope-searches/init.lua @@ -21,6 +21,19 @@ function M.my_copy_relative_path(prompt_bufnr) local selected_file = Path:new(selection.cwd, selection.value):__tostring() + local relative_path = M.relative_path_to_file(current_file_dir, selected_file) + vim.fn.setreg("*", relative_path) + -- display a message with the relative path + vim.api.nvim_echo({ { "Copied: ", "Normal" }, { relative_path, "String" } }, true, {}) + + actions.close(prompt_bufnr) +end + +---@param current_file_dir string +---@param selected_file string +---@return string +function M.relative_path_to_file(current_file_dir, selected_file) + local telescopeUtils = require("telescope.utils") local stdout, ret, stderr = telescopeUtils.get_os_command_output({ "grealpath", "--relative-to", current_file_dir, selected_file }) @@ -30,11 +43,8 @@ function M.my_copy_relative_path(prompt_bufnr) end local relative_path = stdout[1] - vim.fn.setreg("*", relative_path) - -- display a message with the relative path - vim.api.nvim_echo({ { "Copied: ", "Normal" }, { relative_path, "String" } }, true, {}) - actions.close(prompt_bufnr) + return relative_path end ---@return string?