aicopy - a helpful pbcopy wrapper for ai context Posted on June 20, 2024 by Dave Fowler

As someone who frequently communicates with AI, I found myself needing a quick and efficient way to copy the contents of a directory, including filenames, to the clipboard. This need arose from my frequent interactions with AI, where providing context from multiple files was crucial. To address this, I created aicopy.

What is aicopy?

aicopy is a simple command-line tool for macOS that copies the contents of a directory or a file, along with their filenames, to the clipboard. This is especially useful for sharing code snippets or directories of code files in a structured format, making it easier for AI or other automated systems to parse and understand the data.

Installation

  1. Tap the repository:

    brew tap davefowler/aicopy
  2. Install aicopy:

    brew install aicopy

Manual Installation

  1. Download the installation script:

    curl -s https://raw.githubusercontent.com/davefowler/aicopy/main/install-aicopy.sh | bash

This will download the aicopy script and place it in /usr/local/bin.

Usage

Using aicopy is straightforward. You can copy the contents of a directory, a single file, or use patterns to specify multiple files.

Copy a Directory

To copy all files in a directory:

aicopy somedir

To copy a single file:

aicopy somedir/yourfile.txt

Copy Multiple Files with a Pattern

To copy multiple files matching a pattern:

aicopy somedir/*.txt

Output Format

The copied content is structured with clear delimiters, making it easy for AI or automated systems to parse:

=== FILENAME_START ===
/path/to/file1.txt
=== FILENAME_END ===
=== CONTENT_START ===
<content of file1.txt>
=== CONTENT_END ===

=== FILENAME_START ===
/path/to/file2.txt
=== FILENAME_END ===
=== CONTENT_START ===
<content of file2.txt>
=== CONTENT_END ===

Why aicopy?

The need for aicopy came from my frequent interactions with AI, where providing context from multiple files was often necessary. This tool simplifies the process, making it efficient and error-free. Whether you’re sharing code snippets or entire directories of files, aicopy structures the output in a way that is easy to understand and use.

You can find aicopy on GitHub. Feel free to use it, modify it, or contribute to its development:

GitHub Repository for aicopy

Acknowledgements

While developing aicopy, I had the assistance of AI, which helped streamline the creation and release process. This collaboration was incredibly empowering, showing how AI can assist in developing and sharing useful software tools quickly and efficiently. AI can be fun to work with but I'm still quite a Doomer.