nvim neotree copy path
This commit is contained in:
@@ -587,6 +587,45 @@ local function makespec_oil()
|
||||
end
|
||||
|
||||
local function makespec_neotree()
|
||||
local function copy_path(state)
|
||||
-- NeoTree is based on [NuiTree](https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/tree)
|
||||
-- The node is based on [NuiNode](https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/tree#nuitreenode)
|
||||
local node = state.tree:get_node()
|
||||
local filepath = node:get_id()
|
||||
local filename = node.name
|
||||
local modify = vim.fn.fnamemodify
|
||||
|
||||
local results = {
|
||||
filepath,
|
||||
modify(filepath, ":."),
|
||||
modify(filepath, ":~"),
|
||||
filename,
|
||||
modify(filename, ":r"),
|
||||
modify(filename, ":e"),
|
||||
}
|
||||
|
||||
vim.ui.select({
|
||||
"1. Absolute path: " .. results[1],
|
||||
"2. Path relative to CWD: " .. results[2],
|
||||
"3. Path relative to HOME: " .. results[3],
|
||||
"4. Filename: " .. results[4],
|
||||
"5. Filename without extension: " .. results[5],
|
||||
"6. Extension of the filename: " .. results[6],
|
||||
}, { prompt = "Choose to copy to clipboard:" }, function(choice)
|
||||
if choice then
|
||||
local i = tonumber(choice:sub(1, 1))
|
||||
if i then
|
||||
local result = results[i]
|
||||
vim.fn.setreg('+', result)
|
||||
vim.notify("Copied: " .. result)
|
||||
else
|
||||
vim.notify("Invalid selection")
|
||||
end
|
||||
else
|
||||
vim.notify("Selection cancelled")
|
||||
end
|
||||
end)
|
||||
end
|
||||
return {
|
||||
{
|
||||
"nvim-neo-tree/neo-tree.nvim",
|
||||
@@ -613,6 +652,7 @@ local function makespec_neotree()
|
||||
window = {
|
||||
mappings = {
|
||||
["O"] = "system_open",
|
||||
["Y"] = copy_path,
|
||||
["h"] = function(state)
|
||||
local node = state.tree:get_node()
|
||||
if node.type == "directory" and node:is_expanded() then
|
||||
|
||||
Reference in New Issue
Block a user