<h1 align="center">bath 🚿</h1>
<p align="center">
<a href="https://github.com/4thel00z/bath/actions/workflows/ci.yml">
<img alt="CI" src="https://github.com/4thel00z/bath/actions/workflows/ci.yml/badge.svg" />
</a>
<a href="https://crates.io/crates/bath">
<img alt="Crates.io" src="https://img.shields.io/crates/v/bath.svg" />
</a>
<a href="https://github.com/4thel00z/bath/blob/master/LICENSE">
<img alt="License" src="https://img.shields.io/github/license/4thel00z/bath" />
</a>
</p>
`bath` is a terminal UI (TUI) tool for managing environment-variable profiles (e.g. `PATH`, compiler flags, and linker flags) backed by SQLite.
<p align="center">
<img src="assets/bath.gif" alt="bath demo" />
</p>
## Features
- **Profiles in SQLite**: store multiple named profiles and switch/export them consistently
- **Interactive TUI**: edit variables with live preview of the resulting export output
- **Export for shell eval**: print `export ...` statements for the selected profile
- **Modes**: prepend/append/replace behavior per variable
- **Known-var catalog**: ~220 env vars plus ~30 name patterns from AWS, Postgres, MySQL, Docker, Kubernetes, Go, Rust, Python, Node, Java, Terraform, GCP, Azure, Git and more, with their kind and separator filled in; extend it with your own
- **Highlighting**: `export` lines, previews and the `:` command line are colored using the active theme
- **Crash-safe terminal**: raw mode and the alternate screen are always restored, even on errors or panics
## Installation
```bash
cargo install bath
```
## Usage
- **TUI mode**:
```bash
bath
```
- **TUI navigation (k9s-style)**
- **Views**: single active view with an always-visible bottom **Details** pane.
- **Global keys**
- **`:`**: command palette (jump views / run commands; the suggestion list scrolls with your selection)
- **`/`**: filter current view (live while typing, `Enter` applies, `Esc` cancels/clears)
- **`j`/`k`** or **Arrow keys**: move selection
- **`Enter`**: drill into the selection (e.g. a variable's parts)
- **`Tab`**: cycle through views
- **`g`/`End`**: jump to bottom
- **`G`/`Home`**: jump to top
- **`q`** / **`Ctrl+C`**: quit
- **Common `:` commands**
- **`:profiles` `:vars` `:parts` `:items` `:defs` `:preview` `:export` `:help`**
- **`:use <profile>`**
- **`:themes`** (list available theme presets)
- **`:theme <name>`** (switch theme; also persists to config)
- **`:new-var`** (create a custom env var definition)
- **`:new-item`** (create an item)
- **`:quit`**
- **Vars view**
- While filtering with **`/`**, known catalog vars you have not added yet appear as dimmed **`+`** rows tagged with their group (e.g. `/pg` lists `PGHOST`, `PGPORT`, …). A typed name that only matches a pattern (e.g. `PGFOO` via `PG*`) is offered too.
- **`Enter`** on a `+` row opens its parts; the var definition (with the catalog's kind and separator) is saved together with its first value, so browsing never leaves empty definitions behind.
- **`:new-var` dialog**
- Typing a name suggests catalog matches (**`Up`/`Down`** to pick, **`Tab`** to complete); kind and separator are filled in from the catalog until you change them yourself.
- **Parts view** (a variable's entries)
- **`a`/`e`/`d`/`y`**: add / edit / delete / duplicate a part (scalar variables are guarded against gaining a second entry)
- **`J`/`K`**: reorder parts (disabled while a filter is active)
- **`m`**: pick up a part to move — a persistent **HOLDING** indicator appears and the part stays in place until you drop it with **`p`**, so quitting or pressing `Esc` mid-move never loses anything
- **Profiles view**
- **`A`/`E`/`D`**: add / rename / delete a profile (duplicate and empty names are rejected)
- **Dialogs**
- **`Ctrl+T`**: toggle the kind field (`t` types normally into text fields)
- **`Esc`**/**`Ctrl+C`**: cancel; empty values and separators are rejected on save
- **Theming**
- Config file: **`~/.config/bath/config.toml`** (or `$XDG_CONFIG_HOME/bath/config.toml`)
- Example:
```toml
[theme]
preset = "dracula"
# Optional overrides (accepts oklch(...) like DaisyUI, or #RRGGBB)
primary = "oklch(75% 0.18 346)"
base_100 = "#0b0f19"
```
- **Your own known vars**
- File: **`~/.config/bath/catalog.toml`** (or `$XDG_CONFIG_HOME/bath/catalog.toml`)
- Entries with the same `name` or `pattern` as a built-in one replace it; your patterns are tried before the built-in ones. Exact names always win over patterns. If the file cannot be parsed, bath starts with the built-in catalog and shows the error in the status line.
- Example:
```toml
[[var]]
name = "ACME_API_TOKEN"
kind = "scalar"
group = "acme"
[[var]]
pattern = "ACME_*_HOSTS" # `*` matches any characters
kind = "list"
separator = "," # lists default to ":"
group = "acme"
```
- **Demo**
The README includes a GIF (`assets/bath.gif`) showing the TUI in action.
- **Export a profile**:
```bash
bath export my_profile
```
- **Eval in your shell**:
```bash
eval "$(bath export my_profile)"
```
- **Choose export mode** (`prepend` is default):
```bash
bath export my_profile --mode append
```
- **Export help**:
```bash
bath export --help
```
## Data storage
Bath stores profiles in a SQLite database at:
- `~/.bath.db`
## Development
### pre-commit hooks
This repository includes a `.pre-commit-config.yaml` to run basic checks locally (formatting, clippy, tests).
```bash
pipx install pre-commit
pre-commit install
pre-commit run -a
```
### CI
GitHub Actions runs the following on every push and pull request:
- `cargo fmt --check`
- `cargo clippy -- -D warnings`
- `cargo test`
### Releasing (crates.io)
Releases are automated with `release-plz` (it opens a release PR and publishes to crates.io after merge).
- **Required GitHub setting**: in `Settings → Actions → General`, set workflow permissions to allow GitHub Actions to create and approve pull requests. See the official quickstart: https://release-plz.dev/docs/github/quickstart
- **Required secret**: `CARGO_REGISTRY_TOKEN` (crates.io token with scopes `publish-new` and `publish-update`), used by `.github/workflows/release-plz.yml`.
## License
GPL-3.0. See `LICENSE`.