An open API service indexing awesome lists of open source software.

https://github.com/liuzhen9320/psreadline-cleaner

A Python tool to clean, deduplicate, and filter Windows PowerShell console history (ConsoleHost_history.txt).
https://github.com/liuzhen9320/psreadline-cleaner

cleaner history-management powershell python python312

Last synced: 2 days ago
JSON representation

A Python tool to clean, deduplicate, and filter Windows PowerShell console history (ConsoleHost_history.txt).

Awesome Lists containing this project

README

          

# PS History Cleaner

A Python tool to clean, deduplicate, and filter Windows PowerShell console history (`ConsoleHost_history.txt`).

## What it does

1. **Reads** the raw PowerShell history file.
2. **Exactly deduplicates** – keeps the last occurrence of each command.
3. **Computes similarity** between commands using a trie‑based prefix analysis (outputs a `.txt` report).
4. **Fuzzy deduplicates** – removes commands that are ≥80% prefix of a longer kept command.
5. **Filters out**:
- Help commands (`--help`, `-h`, `git help`, etc.)
- Install commands (`npm install`, `pip install`, `go get`, etc.) – also reports per‑package manager.
- Runner commands (`npx`, `go run`, `bun run`, `git clone`, etc.)
- Low‑frequency commands (raw total <10 occurrences).
6. **Outputs** the final cleaned command list to `ConsoleHost_history_dryrun.txt` along with detailed statistics.

## Why use it?

- Reduce noise from repetitive help/install/runner commands.
- Keep only the most representative commands for your workflow.
- Understand your command usage patterns (raw vs. kept counts per command word).

## Usage

1. Place the script in the same folder as `ConsoleHost_history.txt` (default PowerShell history path: `%USERPROFILE%\AppData\Roaming\Microsoft\Windows\PowerShell\ConsoleHost_history.txt`).
2. Run:
```bash
python history_cleaner.py
```
3. Review the generated files:
- `ConsoleHost_history_analysis.txt` – similarity matrix.
- `ConsoleHost_history_dryrun.txt` – final filtered commands.
- Console output – filtering statistics and command word summaries.

## Requirements

- Python 3.7+
- No external dependencies (uses only standard library).

## Customization

You can modify the `threshold` in `fuzzy_dedupe()` (default 0.8) or adjust the frequency filter (`<10` in `main()`).