Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

jondot/bhgrep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

bhgrep πŸ”

Fuzzy search over your local browser history across all browsers

CI License: MIT Rust Crates.io

bhgrep is a blazing-fast command-line tool that lets you search through your browser history across Chrome, Firefox, Safari, and Edge with fuzzy matching, regex support, and an interactive TUI.

✨ Features

  • πŸ” Fuzzy Search - Find pages even with typos or partial matches
  • 🎯 Regex Support - Powerful pattern matching for advanced queries
  • πŸ–₯️ Interactive TUI - Beautiful terminal interface for browsing results
  • πŸ“‹ CLI Mode - Script-friendly output with JSON, plain text, or URL-only formats
  • 🌐 Multi-Browser - Automatically searches Chrome, Firefox, Safari, and Edge
  • ⚑ Smart Scoring - Prioritizes recent and frequently visited pages
  • πŸ”— Quick Actions - Open URLs or copy to clipboard with a single keystroke
  • πŸš€ Fast - Efficient indexing and caching for instant results

πŸ“¦ Installation

From Source

git clone https://github.com/jondot/bhgrep.git
cd bhgrep
cargo build --release

The binary will be at target/release/bhgrep. You can add it to your PATH:

sudo cp target/release/bhgrep /usr/local/bin/

Using Cargo

cargo install bhgrep

πŸš€ Quick Start

Interactive Mode (Default)

Simply run bhgrep without arguments to enter interactive mode:

bhgrep

Keyboard shortcuts:

  • Type to search
  • Enter: Open selected URL in browser
  • y: Copy URL to clipboard
  • Esc or q: Quit
  • ↑/↓: Navigate results
  • Ctrl+U: Clear search

CLI Mode

Search with a query:

bhgrep --query "rust programming"

πŸ“– Usage

Basic Examples

# Search and output as JSON
bhgrep -q "rust" --format json

# Get only URLs (perfect for scripting)
bhgrep -q "tutorial" --format url-only

# Open first result in browser
bhgrep -q "github" --open

# Copy first result URL to clipboard
bhgrep -q "stackoverflow" --copy

# Search only Chrome history
bhgrep -q "documentation" --browser chrome

# Use regex for pattern matching
bhgrep --mode regex -q "github\.com/.*/.*" --format url-only

Advanced Examples

# Find all GitHub repos you've visited
bhgrep -q "github.com" --format url-only | grep -E "github\.com/[^/]+/[^/]+" | sort -u

# Export full history as JSON for analysis
bhgrep -q "" --format json --limit 10000 > history.json

# Search with custom limit
bhgrep -q "documentation" --limit 50

# Use database mode for faster startup (slower queries)
bhgrep -q "search term" --mode db

Output Formats

  • plain (default): Human-readable format with title, URL, and metadata
  • json: JSON format perfect for scripting and automation
  • url-only: Just URLs, one per line

🎯 Use Cases

For Developers

# Quick alias for documentation lookup
alias doc='bhgrep -q "$1" --format url-only --open'

# Find all Stack Overflow answers you've visited
bhgrep -q "stackoverflow.com" --format url-only

# Collect resources for a project
bhgrep -q "myproject" --format json | jq '.[] | .url' > resources.txt

For Security Researchers

# Export sensitive history for analysis
bhgrep -q "token=" --format json --limit 50000 > full_history.json

# Find visits to specific domains
bhgrep --mode regex -q "example\.com" --format json

# Timeline analysis
bhgrep -q "target" --format json | jq -r '.[] | "\(.last_visit) | \(.url)"' | sort

🌐 Supported Browsers

  • βœ… Google Chrome - Full support
  • βœ… Mozilla Firefox - Full support
  • βœ… Safari - Full support (macOS only)
  • βœ… Microsoft Edge - Full support

The tool automatically detects available browsers and searches across all of them.

πŸ”§ Command-Line Options

USAGE:
    bhgrep [OPTIONS]

OPTIONS:
    -q, --query <QUERY>        Search query (enables non-interactive mode)
    -n, --limit <LIMIT>        Limit number of results [default: 10]
    --format <FORMAT>           Output format: plain, json, or url-only [default: plain]
    --open                      Open first result in browser
    --copy                      Copy first result URL to clipboard
    --browser <BROWSER>         Filter by browser: chrome, firefox, safari, or edge
    --mode <MODE>               Search mode: fuzzy, db, or regex [default: fuzzy]
    --cache-freshness <SECS>    Cache freshness in seconds [default: 600]
    -h, --help                  Print help information
    -V, --version               Print version information

Search Modes

  • fuzzy (default): Loads all history to memory, then performs fast fuzzy search
  • db: Queries database directly on each search (faster startup, slower queries)
  • regex: Loads all history to memory, then performs regex pattern matching

πŸ—οΈ Building from Source

Prerequisites

  • Rust 1.70 or later
  • Cargo

Build

# Debug build
cargo build

# Release build (optimized)
cargo build --release

Run Tests

cargo test

Run Linter

cargo clippy --all-targets --all-features -- -D warnings

Check Formatting

cargo fmt --all -- --check

πŸ“ Project Structure

bhgrep/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ browsers/          # Browser-specific history readers
β”‚   β”‚   β”œβ”€β”€ chrome.rs
β”‚   β”‚   β”œβ”€β”€ firefox.rs
β”‚   β”‚   β”œβ”€β”€ safari.rs
β”‚   β”‚   └── edge.rs
β”‚   β”œβ”€β”€ search.rs          # Search algorithms (fuzzy, regex)
β”‚   β”œβ”€β”€ scoring.rs         # Scoring and ranking logic
β”‚   β”œβ”€β”€ tui.rs            # Terminal UI
β”‚   β”œβ”€β”€ output.rs         # Output formatting
β”‚   └── main.rs           # CLI entry point
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml        # CI/CD pipeline
└── Cargo.toml

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Clone the repository
git clone https://github.com/jondot/bhgrep.git
cd bhgrep

# Run tests
cargo test

# Run with logging
RUST_LOG=debug cargo run -- -q "test"

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“Š Performance

bhgrep is optimized for speed:

  • Fuzzy mode: Fast queries after initial load (~100ms for 10k entries)
  • DB mode: Fast startup, queries database directly
  • Smart caching: Browser databases are cached to avoid repeated file operations
  • Efficient scoring: Only clones entries that make it to final results

πŸ› Troubleshooting

No results found

  • Make sure you have browser history in supported browsers
  • Try a broader search query
  • Check that browsers are installed and have history

Permission errors (macOS)

  • Grant Full Disk Access to Terminal/iTerm in System Preferences
  • Safari requires Full Disk Access to read its history database

Slow performance

  • Use --mode db for faster startup if you have large history
  • Reduce --limit for faster results
  • Consider using --browser to search only specific browsers

πŸ”— Related Projects


Made with ❀️ by @jondot

If you find bhgrep useful, please consider giving it a ⭐ on GitHub!

About

like ripgrep but for browser history

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages