Skip to main content

Prepare multiple source code files for AI prompts, with clipboard support.

Project description

aiprep

Overview

The aiprep script is a versatile tool designed to streamline interactions with AI tools. It allows you to combine multiple files into a single, formatted output that is ready to paste into an AI prompt. The script handles filenames and code block delimiters (backticks) to ensure proper formatting, preserving the context and structure of your files when interacting with AI tools.

A key feature of this script is its ability to reformat markdown-style code blocks. This ensures that the pasted content renders properly within AI tools, avoiding issues like losing the code block formatting or having markdown render incorrectly in responses.

Features

  • Combine multiple files into a single, clipboard-ready output.
  • Format the output with filenames and backticks for code blocks.
  • Recursively collect files matching patterns with --recursive.
  • Remove or re-add backticks to ensure correct rendering in AI prompts and responses.
  • Skip invalid files with a warning, ensuring smooth processing.

Why Modify Codeblocks?

When pasting formatted content into AI tools, the rendered markdown can sometimes interfere with the interaction:

  • If markdown is left unprocessed, code blocks might not render correctly when AI responds.
  • By removing and re-adding code block delimiters (backticks), the script ensures that your input retains the correct format and structure. This allows the AI to display and interpret code blocks correctly without inadvertently rendering markdown in its output.

The --deblock and --reblock options allow you to address this issue:

  • -d, --deblock: Replace triple backticks with double backticks (```) to prevent markdown rendering in AI outputs.
  • -r, --reblock: Restore triple backticks after processing to re-enable proper code block formatting.

Installation

  1. Ensure Python 3 is installed on your system.
  2. Install xclip for clipboard functionality:
    sudo apt-get install xclip
    
  3. Download or clone the script into your preferred directory.
  4. Make the script executable:
    chmod +x aiprep
    

Usage

Run the script with the desired functionality using the following options:

Options

  • -c, --combine: Combine multiple files into a single clipboard-friendly format with filenames and codeblocks.
  • -d, --deblock: Replace triple backticks with double backticks (```) in the specified files.
  • -r, --reblock: Replace double backticks (```) with triple backticks in the specified files.
  • --recursive: Recursively include files matching the given glob patterns.
  • -h, --help: Show usage instructions.

Examples

Combine Files into Clipboard

./aiprep -c file1.py file2.py file3.py

Recursively Combine All .py Files

./aiprep -c --recursive "*.py"

This combines the content of all Python files in the current directory and subdirectories, formats them with filenames and triple backticks, and copies the result to your clipboard.

Modify Codeblocks

Replace triple backticks with double backticks:

./aiprep -d file1.md file2.md

Restore double backticks to triple backticks:

./aiprep -r file1.md file2.md

Help

./aiprep -h

Expected Output (Copied to Clipboard)

For -c, the combined output will have the following format:

file1.py:

<contents of file1.py>

file2.py:

<contents of file2.py>

file3.py:

<contents of file3.py>

Notes

  • Ensure all specified files exist. Non-existent or invalid file paths will be skipped with a warning.
  • Use the --deblock and --reblock options carefully to handle code block rendering issues when interacting with AI tools.
  • --recursive works with glob patterns (e.g., "*.py") to collect matching files in all directories.

Purpose

This script is designed to optimize workflows for loading multiple source code files into AI tools. By preparing files in a clipboard-ready format and ensuring proper rendering of code blocks, it eliminates common issues with markdown formatting in AI responses, allowing you to focus on content rather than formatting.

License

Feel free to use, modify, and distribute this script as needed. No restrictions apply.

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

aiprep-1.0.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

aiprep-1.0.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file aiprep-1.0.0.tar.gz.

File metadata

  • Download URL: aiprep-1.0.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aiprep-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7116a7aabe7b4a81bb2552c870de8890a71ade44f92fb7299464808b63c2b829
MD5 a0ce30c2b7bb5b96d99e22ce08e51059
BLAKE2b-256 4b75e707da499a916cf92629a6734e24a08a90a3ebef3494ff31a70075ea6e3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiprep-1.0.0.tar.gz:

Publisher: pypi-publish.yml on jeremiah-k/aiprep

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

File details

Details for the file aiprep-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: aiprep-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aiprep-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 345456a5aacda10b24e6de8d4ee50c897d895ff4767d0f2d02e4f50d7b2cfaab
MD5 f50ddd31cbba3fa63fdf2082b0098dab
BLAKE2b-256 f61d7a769caedeaa671a41a07af2a208ddd7f86071fff6da2778c0338446aa75

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiprep-1.0.0-py3-none-any.whl:

Publisher: pypi-publish.yml on jeremiah-k/aiprep

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