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).
- Host: GitHub
- URL: https://github.com/liuzhen9320/psreadline-cleaner
- Owner: liuzhen9320
- License: agpl-3.0
- Created: 2026-05-24T12:23:26.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-05-24T12:24:50.000Z (about 1 month ago)
- Last Synced: 2026-06-23T19:34:55.368Z (4 days ago)
- Topics: cleaner, history-management, powershell, python, python312
- Language: Python
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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()`).