Skip to main content

A CLI tool for extracting and sharing code files and functions. A manual context builder for pasting into llms.

Project description

ggrab - Grug Grab Tool

A CLI tool for manually building context to paste into llm chats. ggrab gathers functions, classes, or entire files wraps them with xml and copies it to the clipboard.

Key Features

  • Smart Extraction: Grab entire files or specific functions/classes
  • Intelligent Autocompletion: File paths and function/class names
  • Token Counting: Built-in token counting for AI context limits
  • Language Support:
    • Python (AST-based extraction)
    • JavaScript (Esprima-based extraction)
    • Other files (full file extraction)

Quick Start

  1. Install:
pip install ggrab    # Basic install
# or
pipx install ggrab   # Recommended

Why pipx? The pipx install is recommended because it:

  • Won't interfere with other Python projects (creates its own venv)
  • Makes ggrab available globally in your terminal
  1. Setup:

Add the following to your shell config file (~/.bashrc, ~/.zshrc, or equivalent):

# Enable ggrab autocompletion
eval "$(register-python-argcomplete ggrab)"

Then reload your shell configuration:

# For bash
source ~/.bashrc

# For zsh
source ~/.zshrc

Usage

# Grab entire files
ggrab file.py

# Extract specific functions
ggrab file.py function1 function2

# Mix multiple files and functions
ggrab file1.py func1 func2 file2.js func3

# Now supports full directories (entire files only)
ggrab directory

# Skip files matching a pattern
ggrab directory/ --ignore *.test.*       # Skip test files
ggrab src/ -i node_modules         # Skip node_modules directory
ggrab . -i *.spec.*                # Skip spec files
ggrab . -i dist                    # Skip dist directory
ggrab . -i *.min.*                 # Skip minified files
ggrab . -i vendor                  # Skip vendor directory
ggrab . -i '*.generated.*'         # Skip generated files (quotes needed for *)
ggrab . -i "**/__pycache__/**"     # Skip Python cache dirs (quotes needed for **)
ggrab . -i '(dist|build)/*'        # Skip multiple dirs (quotes needed for special chars)

# Multiple patterns are also supported
ggrab . -i 'dist/*' -i 'build/*'                     # Can use multiple -i flags too

Press TAB at any time for smart autocompletion:

  • After ggrab: Shows file suggestions
  • After selecting a file: Shows available functions/classes

Examples

# Extract multiple functions from a Python file
$ ggrab utils.py parse_data validate_input
Gathered code from:
  - utils.py, functions: parse_data, validate_input (203 tokens)

===== Combined Snippets (copied to clipboard) =====

# Extract from multiple files
$ ggrab api.py handle_request db.js queryDatabase
Gathered code from:
  - api.py, functions: handle_request (156 tokens)
  - db.js, functions: queryDatabase (178 tokens)

Total tokens across all files: 334

Performance Features

  • Lazy Loading: Heavy dependencies load only when needed
  • Smart Caching: Function/class listings cached for quick access
  • Hybrid Parsing: Fast regex for completion, accurate AST/Esprima for extraction

Requirements

  • Python 3.7+
  • Required: argcomplete
  • Optional but recommended:
    • pyperclip (clipboard support)
    • tiktoken (token counting)
    • esprima (JavaScript parsing)

Advanced Setup

Disable completion sorting (optional):

complete -o nosort -F _python_argcomplete ggrab

For zsh users:

autoload -U compinit && compinit
autoload -U bashcompinit && bashcompinit
eval "$(register-python-argcomplete ggrab)"

Acknowledgments

  • Developed -- ok, prompted into existance by Claude 3.5, o1 pro. Fixed up to working order by Keizo Gates making GrugNotes :)

License

MIT License


For bug reports and feature requests, please open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ggrab-0.1.0a14.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ggrab-0.1.0a14-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file ggrab-0.1.0a14.tar.gz.

File metadata

  • Download URL: ggrab-0.1.0a14.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for ggrab-0.1.0a14.tar.gz
Algorithm Hash digest
SHA256 1a4af07e0194ed4a4d0714cdf98ce155dd7c46c2f733ba388e89fbd5d187d9da
MD5 74724308041fde3d4cd969c76279d459
BLAKE2b-256 604776cb784410910df3fc8977492fe1f03da8a1c3d0fbd7e427facfe1f9c1b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ggrab-0.1.0a14.tar.gz:

Publisher: python-publish.yml on keizo/ggrab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ggrab-0.1.0a14-py3-none-any.whl.

File metadata

  • Download URL: ggrab-0.1.0a14-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for ggrab-0.1.0a14-py3-none-any.whl
Algorithm Hash digest
SHA256 98bf7943d33ee29e1f972ac9996c112ebb1038eeb97112a1e82e2b3f26b3ee83
MD5 9990b27be576ae82691ef26d54f30025
BLAKE2b-256 e47c0b5b47a319716936052b7677ffa7d45cb2e6d066f6897f438d5fee73a503

See more details on using hashes here.

Provenance

The following attestation bundles were made for ggrab-0.1.0a14-py3-none-any.whl:

Publisher: python-publish.yml on keizo/ggrab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page