Merge pull request #854 from jdvr/master

#194 Connect `rm` command to platform's recycle bin
This commit is contained in:
Jonathan Turner
2019-10-21 05:16:48 +13:00
committed by GitHub
4 changed files with 23 additions and 3 deletions

View File

@ -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(

View File

@ -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)?;