diff --git a/src/ops/list.rs b/src/ops/list.rs index b04ab6b..40a4bf5 100644 --- a/src/ops/list.rs +++ b/src/ops/list.rs @@ -1,4 +1,5 @@ use std::path::PathBuf; +use std::env; use anyhow::Result; @@ -12,17 +13,28 @@ pub struct ListOptions { /// By default, this is your home directory's trash ($XDG_DATA_HOME/Trash) #[structopt(long = "trash-dir", parse(from_os_str))] trash_dir: Option, + + /// List all files in the trash (by default, only files in the current + /// directory are listed) + #[structopt(short = "a", long = "all")] + all: bool, } /// List the contents of a trash directory pub fn list(options: ListOptions) -> Result<()> { - let trash_dir = TrashDir::from_opt(options.trash_dir); + let trash_dir = TrashDir::from_opt(options.trash_dir.as_ref()); + let current_dir = env::current_dir()?; let mut files = trash_dir .iter() .unwrap() .filter_map(|entry| match entry { - Ok(info) => Some(info), + Ok(info) => { + if !options.all && !info.path.starts_with(¤t_dir) { + return None; + } + Some(info) + } Err(err) => { eprintln!("failed to get file info: {:?}", err); None