From b3192ddc977e5424c244ba11df8bce85a417ea64 Mon Sep 17 00:00:00 2001 From: Gabriel B Gutierrez Date: Thu, 14 Oct 2021 17:03:39 -0300 Subject: [PATCH] fix operating more than 2 file at the same time --- crates/nu-command/src/filesystem/cp.rs | 9 ++++++--- crates/nu-command/src/filesystem/mv.rs | 9 ++++++--- crates/nu-command/src/filesystem/rm.rs | 8 +++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/crates/nu-command/src/filesystem/cp.rs b/crates/nu-command/src/filesystem/cp.rs index 3abeee4588..730725b707 100644 --- a/crates/nu-command/src/filesystem/cp.rs +++ b/crates/nu-command/src/filesystem/cp.rs @@ -74,7 +74,7 @@ impl Command for Cp { } if interactive && !force { - let mut remove_index: Vec = vec![]; + let mut remove: Vec = vec![]; for (index, file) in sources.iter().enumerate() { let prompt = format!( "Are you shure that you want to copy {} to {}?", @@ -90,10 +90,13 @@ impl Command for Cp { let input = get_confirmation(prompt)?; if !input { - remove_index.push(index); + remove.push(index); } } - for index in remove_index { + + remove.reverse(); + + for index in remove { sources.remove(index); } diff --git a/crates/nu-command/src/filesystem/mv.rs b/crates/nu-command/src/filesystem/mv.rs index 30dfbb7bb0..70869d1d90 100644 --- a/crates/nu-command/src/filesystem/mv.rs +++ b/crates/nu-command/src/filesystem/mv.rs @@ -60,7 +60,7 @@ impl Command for Mv { } if interactive && !force { - let mut remove_index: Vec = vec![]; + let mut remove: Vec = vec![]; for (index, file) in sources.iter().enumerate() { let prompt = format!( "Are you shure that you want to move {} to {}?", @@ -76,10 +76,13 @@ impl Command for Mv { let input = get_confirmation(prompt)?; if !input { - remove_index.push(index); + remove.push(index); } } - for index in remove_index { + + remove.reverse(); + + for index in remove { sources.remove(index); } diff --git a/crates/nu-command/src/filesystem/rm.rs b/crates/nu-command/src/filesystem/rm.rs index 4d81616b5a..0aca771474 100644 --- a/crates/nu-command/src/filesystem/rm.rs +++ b/crates/nu-command/src/filesystem/rm.rs @@ -127,7 +127,7 @@ fn rm(context: &EvaluationContext, call: &Call) -> Result { let force = call.has_flag("force"); if interactive && !force { - let mut remove_index: Vec = vec![]; + let mut remove: Vec = vec![]; for (index, file) in targets.iter().enumerate() { let prompt: String = format!( "Are you sure that you what to delete {}?", @@ -137,11 +137,13 @@ fn rm(context: &EvaluationContext, call: &Call) -> Result { let input = get_confirmation(prompt)?; if !input { - remove_index.push(index); + remove.push(index); } } - for index in remove_index { + remove.reverse(); + + for index in remove { targets.remove(index); }