feat(marks): add bulk move action (#1419)

This commit is contained in:
Kiyan
2022-07-17 08:25:11 +02:00
committed by GitHub
parent 208ce0b153
commit 26512c369f
6 changed files with 70 additions and 13 deletions

View File

@@ -0,0 +1,40 @@
local Marks = require "nvim-tree.marks"
local Core = require "nvim-tree.core"
local utils = require "nvim-tree.utils"
local FsRename = require "nvim-tree.actions.fs.rename-file"
local M = {}
function M.bulk_move()
if #Marks.get_marks() == 0 then
utils.warn "no bookmark to perform bulk move on, aborting."
return
end
vim.ui.input({ prompt = "Move to: ", default = Core.get_cwd(), completion = "dir" }, function(location)
if not location or location == "" then
return
end
if vim.fn.filewritable(location) ~= 2 then
utils.warn(location .. " is not writable, cannot move.")
return
end
local marks = Marks.get_marks()
for _, node in pairs(marks) do
local head = vim.fn.fnamemodify(node.absolute_path, ":t")
local to = utils.path_join { location, head }
FsRename.rename(node, to)
end
if M.enable_reload then
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end)
end
function M.setup(opts)
M.enable_reload = not opts.filesystem_watchers.enable
end
return M

View File

@@ -66,6 +66,7 @@ end
function M.setup(opts)
vim.fn.sign_define(SIGN_NAME, { text = opts.renderer.icons.glyphs.bookmark, texthl = "NvimTreeBookmark" })
require("nvim-tree.marks.bulk-move").setup(opts)
end
return M