feat: Support copy name and path (#385)
This commit is contained in:
@@ -309,4 +309,27 @@ function M.print_clipboard()
|
||||
return api.nvim_out_write(table.concat(content, '\n')..'\n')
|
||||
end
|
||||
|
||||
local function copy_to_clipboard(content)
|
||||
vim.fn.setreg('+', content);
|
||||
vim.fn.setreg('"', content);
|
||||
return api.nvim_out_write(string.format('Copied %s to system clipboard! \n', content))
|
||||
end
|
||||
|
||||
function M.copy_filename(node)
|
||||
return copy_to_clipboard(node.name)
|
||||
end
|
||||
|
||||
function M.copy_path(node)
|
||||
local absolute_path = node.absolute_path
|
||||
local relative_path = utils.path_relative(absolute_path, lib.Tree.cwd)
|
||||
local content = node.entries ~= nil and utils.path_add_trailing(relative_path) or relative_path
|
||||
return copy_to_clipboard(content)
|
||||
end
|
||||
|
||||
function M.copy_absolute_path(node)
|
||||
local absolute_path = node.absolute_path
|
||||
local content = node.entries ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
|
||||
return copy_to_clipboard(content)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user