Skip to content

Commit

Permalink
refactor(nvim): expose linking to a relative file to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas committed Jun 23, 2024
1 parent df54238 commit bf98284
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand All @@ -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?
Expand Down

0 comments on commit bf98284

Please sign in to comment.