swab 0.1.3

A configurable project cleaning tool
swab-0.1.3 is not a library.

swab

release build codecov downloads

swab is a configurable project cleaning tool.

Build artifacts, dependency caches, and generated files accumulate quickly across projects. Running cargo clean in one project, rm -rf node_modules in another, and hunting down .venv directories in a third gets tedious. swab automates this by detecting project types and cleaning them with a single command.

We currently provide 21 built-in rules that cover popular ecosystems: Rust (Cargo), Node.js, Python, Go, .NET, Swift, Elixir, Zig, and many more. The rule system is designed to be easily extended with custom rules to fit any project's specific needs.

Installation

swab should run on any system, including Linux, MacOS, and Windows.

The easiest way to install it is by using cargo, the Rust package manager:

cargo install swab

Otherwise, see below for the complete package list:

Cross-platform

Pre-built binaries

Pre-built binaries for Linux, MacOS, and Windows can be found on the releases page.

Usage

Point swab at one or more directories containing projects to clean:

swab ~/projects

Below is the output of swab --help:

A configurable project cleaning tool

Usage: swab [OPTIONS] [DIRECTORIES]... [COMMAND]

Commands:
  rules  List all available rules
  help   Print this message or the help of the given subcommand(s)

Arguments:
  [DIRECTORIES]...  Directories to scan for projects to clean

Options:
      --dry-run          Enable dry run mode
      --follow-symlinks  Follow symlinks during traversal
  -i, --interactive      Prompt before each task
  -q, --quiet            Suppress all output
  -h, --help             Print help
  -V, --version          Print version

Configuration

You can configure rules in a configuration file. The config file is located at:

  • Linux: ~/.config/swab/config.toml
  • macOS: ~/.config/swab/config.toml
  • Windows: C:\Users\<User>\AppData\Roaming\swab\config\config.toml

To disable specific built-in rules, add them to the disabled list:

[default]
disabled = ["node", "python"]

You can define custom rules with detection patterns and actions:

[[rules]]
id = "my-custom-rule"
name = "My Custom Rule"
detection = "Makefile"
actions = [
  { remove = "build" },
  { remove = "dist" },
]

Detection patterns can use glob syntax and can be combined with logic operators:

detection = "Cargo.toml"
detection = { any = ["package.json", "yarn.lock"] }
detection = { all = ["Dockerfile", "docker-compose.yaml"] }
detection = { not = "*.lock" }

Actions can either remove files/directories or run commands:

actions = [
  { remove = "build" },
  { remove = "**/cache" },
  { command = "make clean" },
]

To customize a built-in rule, define a rule with the same id:

[[rules]]
id = "cargo"
name = "Cargo (custom)"
detection = "Cargo.toml"
actions = [
  { remove = "target" },
  { command = "cargo clean" },
]

Prior Art

This project was inspired by kondo, a similar tool for cleaning project directories. swab aims to provide more flexibility through its configurable rule system and support for custom actions.