<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
- **Profiles as text**: edit a profile like a `.env` file; list vars take one value per indented line
- **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 and checks**: names, values, separators and `export` lines are colored with the active theme; errors are marked per line and block saving
- **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
```
- **Tabs**: `1 <profile>.env` · `2 profiles` · `3 library` · `4 defs` · `5 export` · `6 help`
- **Everywhere**
- **`Tab`** / **`Shift+Tab`**: next / previous tab (`Tab` accepts an open completion first)
- **`Alt+1`…`Alt+6`**: jump to a tab
- **`Ctrl+P`**: commands (also `:` outside the env tab)
- **`Ctrl+S`**: save the env tab (profiles, library and defs save each change right away)
- **`Ctrl+Q`** / **`Ctrl+C`**: quit; asks first when the env tab has unsaved changes (marked `●`)
- **The env tab** edits the active profile as text:
```
PATH = /opt/llvm/bin
$HOME/bin
PGHOST = localhost
ACME [list ','] = a,b
```
- One var per line; indented lines add parts to a list var. Values are split on the var's separator, so pasting `/a:/b` works too.
- Typing a name suggests builtin, your own and catalog vars; **`Tab`** inserts `NAME = `. Catalog vars keep their kind and separator.
- `[list ',']` or `[value]` after a new name sets its kind; it is saved as a def and removed from the text.
- **`Enter`** continues a list at the value column; **`Enter`** on an empty indented line ends the list.
- **`Esc Esc`** discards unsaved changes, **`Ctrl+Z`** undoes, **`Ctrl+K`** / **`Ctrl+D`** delete / duplicate a line, **`Alt+↑`/`Alt+↓`** move it, **`Ctrl+L`** inserts a library value.
- Saving with errors does not write anything and jumps to the first bad line.
- **Profiles tab**: **`Enter`** use, **`a`** add, **`e`** rename, **`y`** duplicate (name prefilled as `<name>-copy`), **`d`** delete, **`/`** filter. Blank and taken names are rejected, and the last profile is kept.
- **Library tab**: a list of values you reuse, with optional tags. **`a`** add, **`e`**/**`Enter`** edit, **`d`** delete, **`y`** copy, **`/`** filter by value or tag. Add and edit take one line: `/opt/llvm/bin # llvm, clang`. The side pane lists the profiles that use the selected value.
- **Defs tab**: a list of your variable definitions. **`a`** add, **`e`**/**`Enter`** edit, **`d`** delete, **`/`** filter. Add and edit take one line: `NAME list ','` or `NAME value`. Deleting or renaming a def that a profile still uses is refused. The side pane lists the catalog, filtered by the same `/` query.
- **Export tab**: the shell output for the active profile; **`m`** cycles prepend/append/replace, **`y`** copies it to the clipboard (OSC 52), and unsaved env changes appear as a diff.
- **Commands** (`Ctrl+P`; aliases separated by `/`)
- `add-var`/`new-var`/`av`, `add-item`/`new-item`/`ai`, `add-def`/`new-def`/`ad`, `add-profile`/`new-profile`/`ap`
- `rm`/`del` `[VAR]`: remove a var from the env file, or the selected value, def or profile
- `use`/`switch <profile>`, `dup`, `rename`, `save`/`w`, `theme <name>`, `q`/`quit`/`exit`
- `env`, `profiles`, `library`/`lib`/`items`, `defs`, `export`, `help`
- **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`.