feat: Support copy name and path (#385)
This commit is contained in:
parent
ef570074e0
commit
d6ab59fd5a
@ -104,6 +104,9 @@ highlight NvimTreeFolderIcon guibg=blue
|
||||
- type `<C-r>` to rename a file and omit the filename on input
|
||||
- type `x` to add/remove file/directory to cut clipboard
|
||||
- type `c` to add/remove file/directory to copy clipboard
|
||||
- type `y` will copy name to system clipboard
|
||||
- type `Y` will copy relative path to system clipboard
|
||||
- type `gy` will copy absolute path to system clipboard
|
||||
- type `p` to paste from clipboard. Cut clipboard has precedence over copy (will prompt for confirmation)
|
||||
- type `d` to delete a file (will prompt for confirmation)
|
||||
- type `]c` to go to next git item
|
||||
@ -162,6 +165,9 @@ lua <<EOF
|
||||
["x"] = tree_cb("cut"),
|
||||
["c"] = tree_cb("copy"),
|
||||
["p"] = tree_cb("paste"),
|
||||
["y"] = tree_cb("copy_name"),
|
||||
["Y"] = tree_cb("copy_path"),
|
||||
["gy"] = tree_cb("copy_absolute_path"),
|
||||
["[c"] = tree_cb("prev_git_item"),
|
||||
["]c"] = tree_cb("next_git_item"),
|
||||
["-"] = tree_cb("dir_up"),
|
||||
|
||||
@ -59,6 +59,9 @@ local keypress_funcs = {
|
||||
rename = fs.rename(false),
|
||||
full_rename = fs.rename(true),
|
||||
copy = fs.copy,
|
||||
copy_name = fs.copy_filename,
|
||||
copy_path = fs.copy_path,
|
||||
copy_absolute_path = fs.copy_absolute_path,
|
||||
cut = fs.cut,
|
||||
paste = fs.paste,
|
||||
close_node = lib.close_node,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -66,6 +66,9 @@ M.View = {
|
||||
["x"] = M.nvim_tree_callback("cut"),
|
||||
["c"] = M.nvim_tree_callback("copy"),
|
||||
["p"] = M.nvim_tree_callback("paste"),
|
||||
["y"] = M.nvim_tree_callback("copy_name"),
|
||||
["Y"] = M.nvim_tree_callback("copy_path"),
|
||||
["gy"] = M.nvim_tree_callback("copy_absolute_path"),
|
||||
["[c"] = M.nvim_tree_callback("prev_git_item"),
|
||||
["]c"] = M.nvim_tree_callback("next_git_item"),
|
||||
["-"] = M.nvim_tree_callback("dir_up"),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user