@@ -317,44 +317,42 @@ fb_actions.copy = function(prompt_bufnr)
317
317
local copy_selections
318
318
copy_selections = function ()
319
319
-- scoping
320
- local selection , name , absolute_path , destination , within_dir
321
-
320
+ local selection , name , destination , exists
321
+ -- TODO disallow copying parent folder into sub-folder
322
322
while index <= # selections do
323
323
selection = selections [index ]
324
- absolute_path = selection :absolute ()
325
- name = selection :absolute () ~= target_dir and selection .filename :sub (# selection :parent ().filename + 2 ) or nil
324
+ name = table.remove (selection :_split ())
326
325
destination = Path :new {
327
326
target_dir ,
328
327
name ,
329
328
}
330
329
-- copying file or folder within original directory
331
- if destination :absolute () == absolute_path then
332
- within_dir = true -- trigger vim.ui.input outside loop
330
+ if destination :exists () then
331
+ exists = true -- trigger vim.ui.input outside loop to avoid interleaving
333
332
break
334
333
else
335
- selection :copy {
336
- destination = destination ,
337
- recursive = true ,
338
- parents = true ,
339
- }
340
- table.insert (copied , name )
334
+ if selection :is_dir () and selection :absolute () == destination :parent ():absolute () then
335
+ local message = string.format (" Copying folder into itself not (yet) supported" , name )
336
+ fb_utils .notify (" actions.copy" , { msg = message , level = " INFO" , quiet = finder .quiet })
337
+ else
338
+ selection :copy {
339
+ destination = destination ,
340
+ recursive = true ,
341
+ parents = true ,
342
+ }
343
+ table.insert (copied , name )
344
+ end
341
345
index = index + 1
342
346
end
343
347
end
344
- if within_dir then
345
- within_dir = false
348
+ if exists then
349
+ exists = false
346
350
vim .ui .input ({
347
- prompt = string.format (" Copying selection within original directory, please provide a new name: " , name ),
348
- default = absolute_path ,
351
+ prompt = string.format (" Target exists, enter new name or <CR/ESC> to overwrite (join) file (dirs)/pass entry: \n " , name ),
352
+ default = destination : absolute () ,
349
353
}, function (input )
350
354
vim .cmd [[ redraw ]] -- redraw to clear out vim.ui.prompt to avoid hit-enter prompt
351
- if input == nil then
352
- local message = string.format (" Copying %s aborted!" , name )
353
- fb_utils .notify (" actions.copy" , { msg = message , level = " INFO" , quiet = finder .quiet })
354
- elseif input == absolute_path then
355
- local message = string.format (" Source and target are identical for copying %s! Skipping." , name )
356
- fb_utils .notify (" actions.copy" , { msg = message , level = " INFO" , quiet = finder .quiet })
357
- else
355
+ if input ~= nil then
358
356
selection :copy {
359
357
destination = input ,
360
358
recursive = true ,
@@ -370,8 +368,8 @@ fb_actions.copy = function(prompt_bufnr)
370
368
local message = " These entries were copied: " .. table.concat (copied , " , " )
371
369
fb_utils .notify (" actions.copy" , { msg = message , level = " INFO" , quiet = finder .quiet })
372
370
end
373
- current_picker :refresh (current_picker .finder , { reset_prompt = true })
374
371
end
372
+ current_picker :refresh (current_picker .finder , { reset_prompt = true })
375
373
end
376
374
copy_selections ()
377
375
end
@@ -469,7 +467,7 @@ fb_actions.goto_parent_dir = function(prompt_bufnr, bypass)
469
467
if not bypass then
470
468
if vim .loop .cwd () == finder .path then
471
469
fb_utils .notify (
472
- " action.rename " ,
470
+ " action.goto_parent_dir " ,
473
471
{ msg = " You cannot bypass the current working directory!" , level = " WARN" , quiet = finder .quiet }
474
472
)
475
473
return
@@ -504,7 +502,7 @@ fb_actions.change_cwd = function(prompt_bufnr)
504
502
505
503
fb_utils .redraw_border_title (current_picker )
506
504
current_picker :refresh (finder , { reset_prompt = true , multi = current_picker ._multi })
507
- fb_utils .notify (" action.rename " , { msg = " Set the current working directory!" , level = " INFO" , quiet = finder .quiet })
505
+ fb_utils .notify (" action.change_cwd " , { msg = " Set the current working directory!" , level = " INFO" , quiet = finder .quiet })
508
506
end
509
507
510
508
--- Goto home directory in |telescope-file-browser.picker.file_browser|.
0 commit comments