mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Add rm_always_trash
option to config (#1869)
* Add `rm_always_trash` option to config * Add `--permanent` flag to `rm` * `rm`: error if both `-t` and `-p` are present Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
ecb67fee40
commit
741d7b9f10
@ -14,6 +14,8 @@ pub struct RemoveArgs {
|
||||
pub recursive: Tagged<bool>,
|
||||
#[allow(unused)]
|
||||
pub trash: Tagged<bool>,
|
||||
#[allow(unused)]
|
||||
pub permanent: Tagged<bool>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@ -29,6 +31,11 @@ impl WholeStreamCommand for Remove {
|
||||
"use the platform's recycle bin instead of permanently deleting",
|
||||
Some('t'),
|
||||
)
|
||||
.switch(
|
||||
"permanent",
|
||||
"don't use recycle bin, delete permanently",
|
||||
Some('p'),
|
||||
)
|
||||
.switch("recursive", "delete subdirectories recursively", Some('r'))
|
||||
.rest(SyntaxShape::Pattern, "the file path(s) to remove")
|
||||
}
|
||||
@ -48,7 +55,7 @@ impl WholeStreamCommand for Remove {
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Delete a file",
|
||||
description: "Delete or move a file to the system trash (depending on 'rm_always_trash' config option)",
|
||||
example: "rm file.txt",
|
||||
result: None,
|
||||
},
|
||||
@ -57,6 +64,11 @@ impl WholeStreamCommand for Remove {
|
||||
example: "rm --trash file.txt",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Delete a file permanently",
|
||||
example: "rm --permanent file.txt",
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -67,7 +79,15 @@ fn rm(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, She
|
||||
let name = args.call_info.name_tag.clone();
|
||||
let shell_manager = args.shell_manager.clone();
|
||||
let (args, _): (RemoveArgs, _) = args.process(®istry).await?;
|
||||
let mut result = shell_manager.rm(args, name)?;
|
||||
let mut result = if args.trash.item && args.permanent.item {
|
||||
OutputStream::one(Err(ShellError::labeled_error(
|
||||
"only one of --permanent and --trash can be used",
|
||||
"conflicting flags",
|
||||
name
|
||||
)))
|
||||
} else {
|
||||
shell_manager.rm(args, name)?
|
||||
};
|
||||
while let Some(item) = result.next().await {
|
||||
yield item;
|
||||
}
|
||||
|
@ -485,6 +485,7 @@ impl Shell for FilesystemShell {
|
||||
rest: targets,
|
||||
recursive,
|
||||
trash: _trash,
|
||||
permanent: _permanent,
|
||||
}: RemoveArgs,
|
||||
name: Tag,
|
||||
path: &str,
|
||||
@ -565,7 +566,8 @@ impl Shell for FilesystemShell {
|
||||
let result;
|
||||
#[cfg(feature = "trash-support")]
|
||||
{
|
||||
result = if _trash.item {
|
||||
let rm_always_trash = config::config(Tag::unknown())?.get("rm_always_trash").map(|val| val.is_true()).unwrap_or(false);
|
||||
result = if _trash.item || (rm_always_trash && !_permanent.item) {
|
||||
trash::remove(f)
|
||||
.map_err(|e| f.to_string_lossy())
|
||||
} else if metadata.is_file() {
|
||||
|
Reference in New Issue
Block a user