Skip to main content

clip-files copies.

Project description

Clip Files 📋📁

Build Coverage GitHub PyPI License Downloads Open Issues

Introducing clip-files - a simple yet useful command-line utility to gather files with a specific extension, format them with their full path, and copy their contents to your clipboard with a token count for GPT-4 usage! Makes it simple to paste in your entire project into e.g., ChatGPT or Claude.ai, now that massive token limits are available.

[ToC] 📚

:star2: Features

  • 📋 Collect files with a specific extension and copy their formatted contents to your clipboard.
  • 📁 Surrounds each file with <file path="...">...</file> for easy parsing by LLMs.
  • 🧮 Calculate and display the total number of tokens used, compatible with GPT-4 tokenization.
  • 🔄 Easily handle and process multiple files in various directories.

:books: Usage

To use clip-files, simply provide the directory to search and the file extension you want to collect:

clip-files --help

Shows the help message:

usage: clip-files [-h] [-i INITIAL_FILE] [-f FILES [FILES ...]] [-m MAXDEPTH]
                  [folder] [extension ...]

Collect files with specific extensions or specific files, format them for clipboard, and count tokens.
There are two main ways to use clip-files:
1. Collecting all files with specific extensions in a folder:
   `clip-files FOLDER EXTENSION [EXTENSIONS ...]`
   Examples:
   - `clip-files . .py`  # all Python files in current directory
   - `clip-files . .py .md .txt`  # all Python, Markdown, and text files in current directory
   - `clip-files src .txt`  # all text files in src directory
   - `clip-files docs .md --initial-file instructions.txt`  # with custom instructions
2. Collecting specific files (can be of different types):
   `clip-files --files FILE [FILE ...]`
   Examples:
   - `clip-files --files src/*.py tests/*.py`  # using shell wildcards
   - `clip-files --files src/main.py docs/README.md`  # different file types
   - `clip-files -f src/*.py -i instructions.txt`  # with custom instructions

Options:
  -f, --files        Specify individual files to include
  -i, --initial-file A file containing initial instructions

Note: When using wildcards (e.g., *.py), your shell will expand them before passing to clip-files.

positional arguments:
  folder                The folder to search for files.
  extension             The file extensions to look for (e.g., .py, .txt). If
                        not provided, includes all non-hidden, non-binary
                        files.

options:
  -h, --help            show this help message and exit
  -i, --initial-file INITIAL_FILE
                        A file containing initial instructions to prepend to
                        the clipboard content. Default is an empty string.
  -f, --files FILES [FILES ...]
                        Specific file paths to include (e.g., --files
                        path/to/file1.py path/to/file2.md). If not provided,
                        all files with the specified extensions are included.
  -m, --maxdepth MAXDEPTH
                        Maximum directory depth to traverse (default: no
                        limit)

clip-files will traverse the specified folder, gather files with the desired extension, format them with their paths, and copy the results to your clipboard along with the token count.

:bulb: Examples

[!TIP] Pro-tip! Just use uv to run clip-files without installing it. For example, uv run clip-files --files *.py will run clip-files in an temporary environment.

There are two main ways to use clip-files:

  1. Collecting all files with a specific extension in a folder:
# Collect all Python files in the current directory
clip-files . .py

# Collect all text files in the documents folder
clip-files documents .txt

# Collect all Python files, including custom initial instructions
clip-files src .py --initial-file instructions.txt
  1. Collecting specific files (can be of different types):
# Collect specific files
clip-files --files src/main.py tests/test_app.py

# Using shell wildcards to select files
clip-files --files src/*.py tests/*.py

# Mix different file types with wildcards
clip-files --files src/*.py docs/*.md config/*.json

# With custom initial instructions
clip-files --initial-file instructions.txt --files src/*.py

Note: When using wildcards (e.g., *.py), your shell will expand them before passing to clip-files.

:hammer_and_wrench: Installation

To install clip-files, use pip:

pip install clip-files

Alternatively, clone the repository:

git clone https://github.com/basnijholt/clip-files.git
cd clip-files
pip install .

Or download the script directly:

wget https://raw.githubusercontent.com/basnijholt/clip-files/main/clip_files.py

and run it using:

python clip_files.py --help

:file_folder: Supported File Types

clip-files supports any file type as long as you provide the correct file extension. Common examples include:

  • .py for Python files
  • .txt for text files
  • .md for Markdown files

:1234: Token Counting

clip-files integrates with the tiktoken library to calculate tokens as they would be counted in GPT-4. This helps in understanding the cost and feasibility of processing the collected text with GPT-4 models.

The script will display the total token count after copying the formatted content to the clipboard.

:heart: Support and Contributions

We welcome feedback and contributions! If you encounter any issues or have suggestions for improvements, please file an issue on our GitHub repository. Contributions via pull requests are also appreciated.

Happy collecting and clipping! 📋📁🎉

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

clip_files-0.4.1.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

clip_files-0.4.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file clip_files-0.4.1.tar.gz.

File metadata

  • Download URL: clip_files-0.4.1.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clip_files-0.4.1.tar.gz
Algorithm Hash digest
SHA256 98e3f714b598cc6fee70a9fcdb1b26a06ceddbf6e73b4b61734e199e7f04a3bf
MD5 c6b4b7e16e8dd9fc15785c5c81d1f9c0
BLAKE2b-256 4e38bac62cf5dbc9860bb5e04443cbec06a2905432900cf9849e388c395458ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for clip_files-0.4.1.tar.gz:

Publisher: release.yml on basnijholt/clip-files

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

File details

Details for the file clip_files-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: clip_files-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clip_files-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 061ba18bc4d86de737a67d9f4ab080adc8f5bfc620c324507f0ec2ebf63a22e8
MD5 01f1aeb9cdb73363e5dfc3985e042983
BLAKE2b-256 e169c8c6e896a3a8bd0c7bb5fa20c2b9abc9d4147412ee5111c4dd23e34605e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for clip_files-0.4.1-py3-none-any.whl:

Publisher: release.yml on basnijholt/clip-files

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