Skip to content
/ rmd Public

Command line utility to safely delete a directory

License

Notifications You must be signed in to change notification settings

angelol/rmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

srmd

Safety‑first command line utility to delete a single directory. srmd is a deliberately limited, safer alternative to rm -rf when you only want to remove one subdirectory of your current working directory.

Why?

The standard rm command can be surprisingly dangerous, especially when combined with -rf and shell completion. For example, imagine you are in /home/user and want to delete the folder music:

rm -rf music/

With tab completion, shells often add a trailing slash. One stray space turns this into a disaster:

rm -rf music /

Now / is also an argument, and you are recursively deleting the root filesystem. srmd exists to not let you do that kind of thing.

Safety guarantees

srmd intentionally has a very small, strict behavior surface:

  • Only direct subdirectories of the current working directory can be deleted.
  • It never traverses to the parent directory and will not delete the current directory itself.
  • It only allows you to delete one directory at a time.
  • It always asks for confirmation and only proceeds on explicit y / Y (default is no).
  • Paths are resolved using canonicalize, so it behaves safely even when symlinks are involved.

If any of these conditions are not met, srmd fails with an error instead of guessing what you meant.

Usage

Basic usage:

srmd path/to/subdir

Examples:

$ pwd
/home/user/projects

$ ls
music  notes  tmp

$ srmd music
delete /home/user/projects/music? [y/N] y
# directory removed

Attempts that will not be allowed:

# Not a direct subdirectory (too high up)
$ srmd /home/user
Error: This is not a subdirectory

# Same directory as CWD
$ srmd .
Error: Not a directory   # or another InvalidInput error, depending on your shell expansion

# Deeper nested path (not a direct child)
$ srmd music/old
Error: This is not a subdirectory

The tool is designed to err on the side of refusing to act rather than risk deleting the wrong thing.

Installation

You need the Rust toolchain installed (cargo, rustc). Then build from source:

cargo build --release
sudo cp ./target/release/srmd /usr/local/bin/

Now srmd should be available in your PATH:

srmd --help  # once CLI flags are added

Testing & coverage

This repository includes both unit tests and CLI integration tests.

  • Run all tests:

    cargo test
    # or
    make test
  • Coverage (requires cargo-llvm-cov and llvm-tools-preview):

    # one-time setup (installs llvm-tools and cargo-llvm-cov where possible)
    make setup
    
    # show coverage summary in the terminal
    make coverage
    
    # generate and open an HTML coverage report (macOS)
    make coverage-html

The tests are intended to keep coverage high (around 90–95%+) across the core logic and CLI behavior, especially around safety checks and error paths.

Contributing

Issues and pull requests are welcome. Some possible areas to help with:

  • Improving error messages and CLI UX.
  • Adding more tests and platform coverage.
  • Packaging for various systems (Homebrew, Nix, AUR, etc.).

Before opening a PR, please:

  • Run the test suite: cargo test
  • Format the code: cargo fmt

License

srmd is licensed under the MIT License. See the LICENSE file for details.

About

Command line utility to safely delete a directory

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published