@@ -17,6 +17,9 @@ local M = {}
1717
1818local function clear_buffer (path )
1919 local buf = utils .find_buffer_by_name (path )
20+ if buf < 1 then
21+ return
22+ end
2023 local alt = vim .fn .bufnr (" #" )
2124 -- Check all windows to see if they are using the buffer
2225 for _ , win in ipairs (vim .api .nvim_list_wins ()) do
@@ -52,10 +55,11 @@ local function create_all_parents(path)
5255end
5356
5457local get_unused_name
55- function get_unused_name (destination , name_chosen_callback )
58+ function get_unused_name (destination , name_chosen_callback , first_message )
5659 if loop .fs_stat (destination ) then
5760 local parent_path , name = utils .split_path (destination )
58- inputs .input (name .. " already exists. Please enter a new name: " , name , function (new_name )
61+ local message = first_message or name .. " already exists. Please enter a new name: "
62+ inputs .input (message , name , function (new_name )
5963 if new_name and string.len (new_name ) > 0 then
6064 local new_path = parent_path .. utils .path_separator .. new_name
6165 get_unused_name (new_path , name_chosen_callback )
@@ -67,7 +71,9 @@ function get_unused_name(destination, name_chosen_callback)
6771end
6872-- Move Node
6973M .move_node = function (source , destination , callback )
70- get_unused_name (destination , function (dest )
74+ local parent_path , name = utils .split_path (source )
75+ get_unused_name (destination or source , function (dest )
76+ create_all_parents (dest )
7177 loop .fs_rename (source , dest , function (err )
7278 if err then
7379 log .error (" Could not move the files" )
@@ -83,18 +89,17 @@ M.move_node = function(source, destination, callback)
8389 end
8490 end )
8591 end )
86- end )
92+ end , ' Move " ' .. name .. ' " to: ' )
8793end
8894
8995-- Copy Node
9096M .copy_node = function (source , _destination , callback )
91- get_unused_name (_destination , function (destination )
92- loop .fs_copyfile (source , destination )
93- local handle
94- handle = loop .spawn (" cp" , { args = { " -r" , source , destination } }, function (code )
95- handle :close ()
96- if code ~= 0 then
97- log .error (" copy failed" )
97+ local parent_path , name = utils .split_path (source )
98+ get_unused_name (_destination or source , function (destination )
99+ create_all_parents (destination )
100+ loop .fs_copyfile (source , destination , function (err )
101+ if err then
102+ log .error (" Could not copy the files" )
98103 return
99104 end
100105 vim .schedule (function ()
@@ -104,7 +109,7 @@ M.copy_node = function(source, _destination, callback)
104109 end
105110 end )
106111 end )
107- end )
112+ end , ' Copy " ' .. name .. ' " to: ' )
108113end
109114
110115-- Create Node
0 commit comments