mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:55:59 +02:00
#194 Added trash crate and send files to the trash using a flag
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(
|
||||
|
@ -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) => {
|
||||
|
Reference in New Issue
Block a user