This Python script allows you to copy the contents of multiple files or entire directories to your clipboard. It's particularly useful for developers who need to quickly share code snippets or project structures.
- Copy contents of individual files to clipboard
- Recursively copy contents of entire directories
- Support for glob patterns to select multiple files or directories
- Respect
.gitignore
rules - Exclude specific files or directories using patterns
- Automatically skip binary files and common lock files (e.g.,
package-lock.json
,yarn.lock
) - Formatted output with file paths and content delimiters
- Python 3.x
pyperclip
library
-
Ensure you have Python 3.x installed on your system.
-
Install the required
pyperclip
library:pip install pyperclip
-
Download the script and save it as
aicopy.py
(or any name you prefer).
python aicopy.py [-h] [-e EXCLUDE] PATH [PATH ...]
PATH
: One or more paths or glob patterns of files or folders to copy.-e EXCLUDE
,--exclude EXCLUDE
: Exclude files or folders matching the given pattern (can be used multiple times).-h
,--help
: Show the help message and exit.
-
Copy a single file:
python aicopy.py path/to/file.py
-
Copy multiple files using glob patterns:
python aicopy.py *.py *.js
-
Copy an entire directory:
python aicopy.py path/to/directory
-
Copy files while excluding specific patterns:
python aicopy.py . -e *.log -e temp/*
- The script processes the provided paths and glob patterns.
- It respects
.gitignore
rules by reading.gitignore
files in the current and parent directories. - Files and directories are processed recursively, skipping those that match exclude patterns or
.gitignore
rules. - Binary files are automatically detected and skipped.
- The content of each valid file is read and formatted with the file path and delimiters.
- All processed content is combined and copied to the clipboard.
- The script automatically ignores the
.git
directory and its contents. - Common lock files like
package-lock.json
andyarn.lock
are automatically ignored. - If no valid files are found or processed, the script will exit with a status code of 1.
Feel free to submit issues or pull requests if you have suggestions for improvements or encounter any bugs.
This project is licensed under the MIT License