#194 Added trash crate and send files to the trash using a flag

This commit is contained in:
jdvr
2019-10-19 00:41:24 +02:00
parent 94429d781f
commit fc1301c92d
4 changed files with 21 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

@ -8,6 +8,7 @@ use crate::prelude::*;
use crate::shell::completer::NuCompleter;
use crate::shell::shell::Shell;
use crate::utils::FileStructure;
use trash as SendToTrash;
use rustyline::completion::FilenameCompleter;
use rustyline::hint::{Hinter, HistoryHinter};
use std::path::{Path, PathBuf};
@ -860,7 +861,7 @@ impl Shell for FilesystemShell {
fn rm(
&self,
RemoveArgs { target, recursive }: RemoveArgs,
RemoveArgs { target, recursive, trash }: RemoveArgs,
name: Tag,
path: &str,
) -> Result<OutputStream, ShellError> {
@ -946,7 +947,11 @@ impl Shell for FilesystemShell {
if path.is_dir() {
std::fs::remove_dir_all(&path)?;
} else if path.is_file() {
std::fs::remove_file(&path)?;
if trash.item {
SendToTrash::remove(path).unwrap();
} else {
std::fs::remove_file(&path)?;
}
}
}
Err(e) => {