# bashistory

Tidies `~/.bash_history` by removing noise commands (ls, cd, etc.), typos, and
duplicates — all while you use the terminal.

## Install

```bash
cargo install bashistory
```

## Usage (live cleaning)

Add to your `~/.bashrc`:

```bash
PROMPT_COMMAND="bashistory 2>/dev/null${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
```

This runs after every command and keeps history clean. The `2>/dev/null` silences
the summary line so it doesn't clutter your prompt.

If you want to see what was cleaned, omit the redirect or use `--stats`:

```bash
bashistory --stats
```

## Options

| Flag | Description |
|------|-------------|
| `-h`, `--help` | Show usage |
| `-V`, `--version` | Show version |
| `-n`, `--dry-run` | Preview what would be removed (no files changed) |
| `-s`, `--stats` | Print removal counts after running |

## What it removes

| Type | Examples | Rule |
|------|---------|------|
| Noise commands | `ls`, `ll`, `cd`, `pwd`, `clear`, `exit`, `history`, `fg`, `bg`, `jobs`, `echo`, `date`, `whoami`, `hostname`, `uname`, `shutdown`, `reboot` | Always removed |
| Case variants | `CLEAR`, `LS`, `CD` | Case‑insensitive match |
| Garbage typos | `clearù`, `ls-l`, `CLEAR!` | Suffix is non‑alphanumeric garbage |
| Old wrong entries | non‑ASCII and 1‑char commands older than 2 weeks | Age‑based cleanup |
| Duplicates | Repeated commands | Keeps only the most recent occurrence |
| Empty lines | < blank > | Stripped away |

**Real commands** that happen to start with a noise prefix (e.g. `lsblk`,
`cdrecord`, `lsmod`) are kept — only garbage suffixes like `ù`, `-`, `!` trigger
typo detection.

A backup is saved to `~/.bash_history.bak` before every write.

## Configuration

### Custom history path

Respects `HISTFILE`:

```bash
export HISTFILE=~/my_history
```

### Extra noise words

Via environment variable (space‑separated):

```bash
export BASHISTORY_EXTRA_NOISE="rm mv cp"
```

Via config file at `~/.config/bashistory/noise.txt` (one per line, `#` comments
supported):

```
docker
kubectl
```

Entries are matched case‑insensitively.

### Max age for typo removal

```bash
export BASHISTORY_MAX_AGE_DAYS=30
```

Default 14 days. Only affects non‑ASCII and 1‑character entries that look like
typos. Valid old commands are always kept.
