diff --git a/Cargo.lock b/Cargo.lock index 763ab1679..510cc4d8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1558,6 +1558,7 @@ dependencies = [ "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "trash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2493,6 +2494,14 @@ dependencies = [ "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "trash" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "typenum" version = "1.11.2" @@ -3093,6 +3102,7 @@ dependencies = [ "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" "checksum toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7aabe75941d914b72bf3e5d3932ed92ce0664d49d8432305a8b547c37227724" +"checksum trash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f24d31505f49e989b1ee2c03c323251f6763d5907d471b71192dac92e323f8" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" "checksum unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" diff --git a/Cargo.toml b/Cargo.toml index 16b8c8586..ce101b52d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,6 +73,7 @@ bigdecimal = { version = "0.1.0", features = ["serde"] } natural = "0.3.0" serde_urlencoded = "0.6.1" sublime_fuzzy = "0.5" +trash = "1.0.0" regex = {version = "1", optional = true } neso = { version = "0.5.0", optional = true } diff --git a/src/commands/rm.rs b/src/commands/rm.rs index ac5aeaae7..c1e671f4b 100644 --- a/src/commands/rm.rs +++ b/src/commands/rm.rs @@ -11,6 +11,7 @@ pub struct Remove; pub struct RemoveArgs { pub target: Tagged, pub recursive: Tagged, + pub trash: Tagged, } 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( diff --git a/src/shell/filesystem_shell.rs b/src/shell/filesystem_shell.rs index f0adeebeb..7b8310141 100644 --- a/src/shell/filesystem_shell.rs +++ b/src/shell/filesystem_shell.rs @@ -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 { @@ -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)?;