Skip to content

A CLI like the GNU version of rm(1) but more modern and designed for humans.

License

Notifications You must be signed in to change notification settings

ericcornelissen/rust-rm

Repository files navigation

rust-rm

A CLI like the GNU version of rm(1) but more modern and designed for humans. Aims to provide an rm command that feels familiar yet is safer and more user friendly. To this end it:

  • Defaults to a dry run, allowing for review before removing;
  • Provides suggestions for next steps, showing how you might continue;
  • Supports moving to thrash, thanks to the trash crate;
  • Offers an excellent CLI experience, thanks to the clap crate;

Usage

By Humans

Start with a dry run:

$ rm file1 file2
Would remove file1
Would remove file2

2 would be removed (use '--force' to remove), 0 errors occurred

And remove if it looks good:

$ rm file1 file2 --force
Removed file1
Removed file2

2 removed, 0 errors occurred

Or go interactive:

$ rm file1 file2 --interactive
Removed file1
Remove regular file file2? [Y/n] _

In Scripts

Use rm with --force - as well as any other flags - to remove things, for example:

rm --force --quiet file1 file2

or, if you want those unfamiliar with rm to not be able to read your script:

rm -fq file1 file2

Build from Source

To build from source you need Rust and Cargo, v1.82 or higher, installed on your system. Then run the command:

just build

Or, if you don't have Just installed, use cargo build directly, for example:

cargo build --release

Build Configuration

The build can be modified to exclude features and obtain a smaller binary. Use:

just features=[FEATURES] build

where [FEATURES] is one or more of:

  • gnu-mode: to include support for the GNU mode.
  • trash: to include support for the --trash option.

For example:

just features=gnu-mode,trash build

Or, to omit all optional features:

just features= build

GNU Mode

The environment variable RUST_RM_GNU_MODE can be used to enable GNU mode. This mode aims to offer some opt-in backwards compatibility with the GNU version of rm(1). It's meant to be useful for scripts. As such, it aims to be compatible with non-failing and semantically valid use cases.

Note: GNU mode is only available if the gnu-mode feature was enabled at compile time.

GNU mode mode will cause rm to:

  • Remove (unlink) files and directories without --force or --interactive.
  • Behave --blind when --force is used (and forget the --blind flag).
  • Be --quiet by default (and forget the --quiet flag).
  • Forget the --trash flag.

It won't cause rm to:

  • Change its stdout/stderr/stdin.
  • Support the -R flag.
  • Support the -I or --interactive=WHEN flags.

Philosophy

The development of this software is guided by the following principles:

  • Defaults should be safe.
  • Program output is for humans.
  • Help the user achieve what they want.

Sources of Inspiration

License

All source code is licensed under the Apache 2.0 license, see LICENSE for the full license text. The contents of documentation is licensed under CC BY 4.0.

About

A CLI like the GNU version of rm(1) but more modern and designed for humans.

Resources

License

Security policy

Stars

Watchers

Forks