mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 12:15:42 +02:00
Merge pull request #854 from jdvr/master
#194 Connect `rm` command to platform's recycle bin
This commit is contained in:
@ -11,6 +11,7 @@ pub struct Remove;
|
||||
pub struct RemoveArgs {
|
||||
pub target: Tagged<PathBuf>,
|
||||
pub recursive: Tagged<bool>,
|
||||
pub trash: Tagged<bool>,
|
||||
}
|
||||
|
||||
impl PerItemCommand for Remove {
|
||||
@ -21,11 +22,12 @@ impl PerItemCommand for Remove {
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("rm")
|
||||
.required("path", SyntaxShape::Pattern)
|
||||
.switch("trash")
|
||||
.switch("recursive")
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Remove a file, (for removing directory append '--recursive')"
|
||||
"Remove a file. Append '--recursive' to remove directories and '--trash' for seding it to system recycle bin"
|
||||
}
|
||||
|
||||
fn run(
|
||||
|
@ -12,6 +12,7 @@ use rustyline::completion::FilenameCompleter;
|
||||
use rustyline::hint::{Hinter, HistoryHinter};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::Ordering;
|
||||
use trash as SendToTrash;
|
||||
|
||||
pub struct FilesystemShell {
|
||||
pub(crate) path: String,
|
||||
@ -860,7 +861,11 @@ impl Shell for FilesystemShell {
|
||||
|
||||
fn rm(
|
||||
&self,
|
||||
RemoveArgs { target, recursive }: RemoveArgs,
|
||||
RemoveArgs {
|
||||
target,
|
||||
recursive,
|
||||
trash,
|
||||
}: RemoveArgs,
|
||||
name: Tag,
|
||||
path: &str,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
@ -943,7 +948,9 @@ impl Shell for FilesystemShell {
|
||||
));
|
||||
}
|
||||
|
||||
if path.is_dir() {
|
||||
if trash.item {
|
||||
SendToTrash::remove(path).unwrap();
|
||||
} else if path.is_dir() {
|
||||
std::fs::remove_dir_all(&path)?;
|
||||
} else if path.is_file() {
|
||||
std::fs::remove_file(&path)?;
|
||||
|
Reference in New Issue
Block a user