From bb08f8aa254750a4ba12a646e7404f6f3b5e13c4 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Sun, 12 Oct 2025 12:26:40 +0545 Subject: [PATCH 1/4] flake: shut the direnv off --- flake.nix | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 7eaeca8..7628222 100644 --- a/flake.nix +++ b/flake.nix @@ -6,23 +6,32 @@ naersk.url = "github:nix-community/naersk"; }; - outputs = { nixpkgs, naersk, ... }: + outputs = + { nixpkgs, naersk, ... }: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; naerskLib = pkgs.callPackage naersk { }; - in { + in + { packages.${system}.default = naerskLib.buildPackage { src = ./.; nativeBuildInputs = [ pkgs.pkg-config ]; }; devShells.${system}.default = pkgs.mkShell { - buildInputs = with pkgs; [ rustc cargo clippy rustfmt rust-analyzer ]; + buildInputs = with pkgs; [ + rustc + cargo + clippy + rustfmt + rust-analyzer + ]; nativeBuildInputs = [ pkgs.pkg-config ]; # env.RUST_SRC_PATH = # "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; }; formatter = pkgs.rustfmt; + DIRENV_LOG_FORMAT = ""; }; } From 6512dba14661ba0298f05d80c118f5b6ca26c42e Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Sun, 12 Oct 2025 13:04:01 +0545 Subject: [PATCH 2/4] refactor: removed the redundant code for displaying the table --- src/main.rs | 65 ++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/src/main.rs b/src/main.rs index 913addd..be63eb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ impl List { } } -fn list_specific_trash(seconds: i64) -> Result<(), trash::Error> { +fn list_specific_trash(seconds: i64) -> Result, trash::Error> { let mut list: Vec = vec![]; let entries = os_limited::list()?; let now = Local::now().timestamp(); @@ -48,39 +48,33 @@ fn list_specific_trash(seconds: i64) -> Result<(), trash::Error> { )); } } - let mut table = Table::new(&list); - table.with(Style::rounded()); - table.modify(Columns::first(), Alignment::right()); - println!("{table}"); - Ok(()) + return Ok(list); } -fn list_trash() { +fn list_trash() -> Result, trash::Error> { let mut list: Vec = vec![]; - match os_limited::list() { - Ok(trash) => { - for entry in trash { - let time_deleted = Local - .timestamp_opt(entry.time_deleted, 0) - .single() - .map(|dt| dt.format("%Y-%m-%d %H:%M:%S").to_string()) - .unwrap_or_else(|| "Unknown time".to_string()); - - list.push(List::new( - entry.name.to_string_lossy().to_string(), - entry.original_path().to_string_lossy().to_string(), - time_deleted, - )) - } - let mut table = Table::new(&list); - table.with(Style::rounded()); - table.modify(Columns::first(), Alignment::right()); - println!("{table}"); - } - Err(e) => { - eprintln!("{}", format!("Failed to list trash entries: {e}").red()) - } + let trash = os_limited::list()?; + for entry in trash { + let time_deleted = Local + .timestamp_opt(entry.time_deleted, 0) + .single() + .map(|dt| dt.format("%Y-%m-%d %H:%M:%S").to_string()) + .unwrap_or_else(|| "Unknown time".to_string()); + + list.push(List::new( + entry.name.to_string_lossy().to_string(), + entry.original_path().to_string_lossy().to_string(), + time_deleted, + )) } + return Ok(list); +} + +fn display_table(list: Vec) { + let mut table = Table::new(&list); + table.with(Style::rounded()); + table.modify(Columns::first(), Alignment::right()); + println!("{table}"); } fn tidy_trash(days: i64) -> Result<(), trash::Error> { @@ -244,11 +238,16 @@ fn main() { if args.is_list() { let seconds = args.get_time_list() * 86400; if seconds == 0 { - list_trash(); + match list_trash() { + Ok(list) => display_table(list), + Err(e) => eprintln!("{}", format!("Failed to list trash entries: {e}").red()), + } + return; } else { - if let Err(e) = list_specific_trash(seconds) { - eprintln!("{}", format!("Failed to list trash entries: {e}").red()); + match list_specific_trash(seconds) { + Ok(list) => display_table(list), + Err(e) => eprintln!("{}", format!("Failed to list trash entries: {e}").red()), } return; } From de4e31d83eccc9f43c6e8ebb54b4f69bb78e0dca Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Sun, 12 Oct 2025 13:13:15 +0545 Subject: [PATCH 3/4] lint: runned cargo clippy and fixed lint errors --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index be63eb5..a9fa664 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,7 +48,7 @@ fn list_specific_trash(seconds: i64) -> Result, trash::Error> { )); } } - return Ok(list); + Ok(list) } fn list_trash() -> Result, trash::Error> { @@ -67,7 +67,7 @@ fn list_trash() -> Result, trash::Error> { time_deleted, )) } - return Ok(list); + Ok(list) } fn display_table(list: Vec) { From ec585dab1403e26a845235f91895b4395c332a62 Mon Sep 17 00:00:00 2001 From: santoshxshrestha Date: Sun, 12 Oct 2025 13:16:22 +0545 Subject: [PATCH 4/4] docs: update the changes in the changelog --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e1a9e..e53f990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.15] - + +### Changed + +- Refactored the logic for lising the trash items and removed the redundant block for lising the items in table + ## [0.1.14] - 2025-10-06 ### Changed - Update dependencies to latest versions -### Fixed +### Fixed + - Fixed the linting issues in the codebase ## [0.1.13] - 2025-09-18