@@ -3,6 +3,7 @@ local utils = require("nvim-tree.utils")
33local events = require (" nvim-tree.events" )
44local notify = require (" nvim-tree.notify" )
55local config = require (" nvim-tree.config" )
6+ local lib = require (" nvim-tree.lib" )
67
78local find_file = require (" nvim-tree.actions.finders.find-file" ).fn
89
4748
4849--- @param node Node
4950--- @param to string
50- function M .rename (node , to )
51+ --- @param opts ? { notify ?: boolean }
52+ function M .rename (node , to , opts )
53+ opts = opts and opts or {}
5154 local notify_from = notify .render_path (node .absolute_path )
5255 local notify_to = notify .render_path (to )
5356
@@ -92,7 +95,9 @@ function M.rename(node, to)
9295 end
9396
9497 if not is_error then
95- notify .info (string.format (" %s -> %s" , notify_from , notify_to ))
98+ if opts .notify ~= false then
99+ notify .info (string.format (" %s -> %s" , notify_from , notify_to ))
100+ end
96101 utils .rename_loaded_buffers (node .absolute_path , to )
97102 events ._dispatch_node_renamed (node .absolute_path , to )
98103 end
@@ -192,4 +197,24 @@ function M.rename_full(node)
192197 prompt_to_rename (node , " :p" )
193198end
194199
200+ --- @param nodes Node[]
201+ --- @param old_part string
202+ --- @param new_part string
203+ function M .bulk_rename (nodes , old_part , new_part )
204+ local prompt_select = string.format (" Substitute '%s' for '%s' in %s files?" , old_part , new_part , # nodes )
205+
206+ lib .prompt (prompt_select .. " Y/n: " , prompt_select , ({ " " , " y" }), { " No" , " Yes" }, " nvimtree_bulk_rename" , function (answer )
207+ utils .clear_prompt ()
208+ if answer == " n" then return end
209+
210+ for _ , node in ipairs (nodes ) do
211+ local new_name = node .name :gsub (old_part , new_part )
212+ local new_full_path = vim .fn .fnamemodify (node .absolute_path , " :h" ) .. " /" .. new_name
213+ M .rename (node , new_full_path , { notify = false })
214+ end
215+
216+ notify .info (string.format (" %s nodes substituted from %s -> %s" , # nodes , old_part , new_part ))
217+ end )
218+ end
219+
195220return M
0 commit comments