Prompt for confirmation when overwriting on cut/copy actions.

This commit is contained in:
Kristijan Husak
2020-07-21 08:56:13 +02:00
parent 37748e7c97
commit 86ff3b725f

View File

@@ -121,8 +121,9 @@ local function do_copy(source, destination)
end end
local handle = luv.fs_scandir(source) local handle = luv.fs_scandir(source)
if type(handle) == 'string' then if type(handle) == 'string' then
return api.nvim_err_writeln(handle) return false, handle
end end
luv.fs_mkdir(destination, source_stats.mode) luv.fs_mkdir(destination, source_stats.mode)
@@ -133,13 +134,8 @@ local function do_copy(source, destination)
local new_name = source..'/'..name local new_name = source..'/'..name
local new_destination = destination..'/'..name local new_destination = destination..'/'..name
if t == 'directory' then local success, msg = do_copy(new_name, new_destination)
local success = do_copy(new_name, new_destination) if not success then return success, msg end
if not success then return false end
else
local success = luv.fs_copyfile(new_name, new_destination)
if not success then return false end
end
end end
return true return true
@@ -173,10 +169,18 @@ local function do_paste(node, action_type, action_fn)
for _, entry in ipairs(clip) do for _, entry in ipairs(clip) do
local dest = destination..'/'..entry.name local dest = destination..'/'..entry.name
local success = action_fn(entry.absolute_path, dest) local dest_stats = luv.fs_stat(dest)
if not success then if dest_stats then
api.nvim_err_writeln('Could not '..action_type..' '..entry.absolute_path) local ans = vim.fn.input(dest..' already exists, overwrite ? y/n: ')
clear_prompt()
if not ans:match('^y') then goto continue end
end end
local success, msg = action_fn(entry.absolute_path, dest)
if not success then
api.nvim_err_writeln('Could not '..action_type..' '..entry.absolute_path..' - '..msg)
end
::continue::
end end
clipboard[action_type] = {} clipboard[action_type] = {}
return refresh_tree() return refresh_tree()