Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
};
}
65 changes: 32 additions & 33 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl List {
}
}

fn list_specific_trash(seconds: i64) -> Result<(), trash::Error> {
fn list_specific_trash(seconds: i64) -> Result<Vec<List>, trash::Error> {
let mut list: Vec<List> = vec![];
let entries = os_limited::list()?;
let now = Local::now().timestamp();
Expand All @@ -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(())
Ok(list)
}

fn list_trash() {
fn list_trash() -> Result<Vec<List>, trash::Error> {
let mut list: Vec<List> = 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,
))
}
Ok(list)
}

fn display_table(list: Vec<List>) {
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> {
Expand Down Expand Up @@ -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;
}
Expand Down
Loading