diff --git a/crates/nu-command/src/filesystem/rm.rs b/crates/nu-command/src/filesystem/rm.rs index 95bb8b2cef..dc6f1c0520 100644 --- a/crates/nu-command/src/filesystem/rm.rs +++ b/crates/nu-command/src/filesystem/rm.rs @@ -13,7 +13,7 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, Spanned, - SyntaxShape, Value, + SyntaxShape, Type, Value, }; const GLOB_PARAMS: glob::MatchOptions = glob::MatchOptions { @@ -48,6 +48,7 @@ impl Command for Rm { ) .switch("recursive", "delete subdirectories recursively", Some('r')) .switch("force", "suppress error when no file", Some('f')) + .switch("quiet", "supress output showing files deleted", Some('q')) // .switch("interactive", "ask user to confirm action", Some('i')) .rest( "rest", @@ -78,6 +79,7 @@ fn rm( let permanent = call.has_flag("permanent"); let recursive = call.has_flag("recursive"); let force = call.has_flag("force"); + let quiet = call.has_flag("quiet"); // let interactive = call.has_flag("interactive"); let ctrlc = engine_state.ctrlc.clone(); @@ -241,6 +243,8 @@ fn rm( Value::Error { error: ShellError::SpannedLabeledError(msg, e.to_string(), span), } + } else if quiet { + Value::Nothing { span } } else { let val = format!("deleted {:}", f.to_string_lossy()); Value::String { val, span } @@ -266,5 +270,6 @@ fn rm( } } }) + .filter(|x| !matches!(x.get_type(), Type::Nothing)) .into_pipeline_data(ctrlc)) }