A tool to collect and format file contents from local directories, Git repositories, or SSH servers.
Project description
hh-c2t
hh-c2t is a versatile command-line tool designed to collect and format file contents from various sources, including local directories, Git repositories, and remote SSH servers. It supports customizable file filtering using a .gitignore-like ignore file and allows users to specify file extensions to include. The output is formatted in Markdown code blocks, making it easy to share or document, and can be copied to the clipboard for convenience.
Features
- Multiple Source Support: Collect files from local directories, Git repositories, or SSH servers.
- Flexible File Filtering: Use a
.gitignore-style ignore file (hh-c2t-ignore) to exclude unwanted files or directories. - Customizable Extensions: Specify which file extensions to include (e.g.,
.py,.txt,.md). - Clipboard Integration: Automatically copy the formatted output to the clipboard (optional).
- Modular Design: Organized into clear modules for maintainability and extensibility.
- Cross-Platform: Works on Windows, macOS, and Linux.
Installation
Install hh-c2t via pip:
pip install hh-c2t
Requirements
- Python 3.9 or higher
- Dependencies (installed automatically):
paramiko(for SSH support)pyperclip(for clipboard functionality)
git(required for cloning Git repositories, must be installed separately)
Usage
Run hh-c2t from the command line with the following syntax:
hh-c2t <source> [ssh_path] [options]
Arguments
source: The source of the files. Can be:- A local directory path (e.g.,
/path/to/dir) - A Git repository URL (e.g.,
https://github.com/user/repo) - An SSH address (e.g.,
username@hostname)
- A local directory path (e.g.,
ssh_path: The remote path on the SSH server (required only for SSH sources).
Options
--password PASSWORD: Password for SSH authentication (optional; will prompt if needed).--no-clipboard: Disable copying the output to the clipboard.--ignore-file FILE: Path to the ignore file (default:hh-c2t-ignore).--extensions EXT: Comma-separated list of file extensions to include (default:.py).
Examples
-
Collect Python files from a local directory:
hh-c2t /path/to/project --extensions .py
This collects all
.pyfiles in/path/to/project, respecting thehh-c2t-ignorefile. -
Collect Python and text files from a Git repository:
hh-c2t https://github.com/user/repo --extensions .py,.txt
Clones the repository and collects
.pyand.txtfiles. -
Collect files from an SSH server:
hh-c2t user@host /remote/path --password mypass --extensions .py
Connects to the SSH server and collects
.pyfiles from/remote/path. -
Use a custom ignore file:
hh-c2t /path/to/dir --ignore-file custom-ignore --extensions .md
Collects
.mdfiles, ignoring patterns specified incustom-ignore.
Ignore File
Create a file named hh-c2t-ignore (or specify a custom file with --ignore-file) to define patterns for files and directories to exclude. The syntax is similar to .gitignore. Example:
__pycache__/*
*.pyc
*.log
dist/*
build/*
*.egg-info
This will exclude Python cache files, logs, and build artifacts.
Output Format
The tool outputs file contents in Markdown code blocks, with each file's relative path as the code block label.
The total character count is displayed, and the output is copied to the clipboard unless --no-clipboard is specified.
Project Structure
The hh-c2t package is organized into modular components:
core.py: Handles file collection from local directories.git_handler.py: Manages cloning and collecting from Git repositories.ssh_handler.py: Collects files from remote SSH servers.filter.py: Implements.gitignore-like file filtering.clipboard.py: Handles clipboard operations.cli.py: Provides the command-line interface.
Contributing
Contributions are welcome! To contribute:
- Fork the repository on GitHub.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes and commit (
git commit -m "Add your feature"). - Push to your fork (
git push origin feature/your-feature). - Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
For questions, bug reports, or feature requests, please open an issue on the GitHub repository or contact Hardy Hu.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hh_c2t-0.1.1.tar.gz.
File metadata
- Download URL: hh_c2t-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a24e8151318a075502dc282fe6c5b01c31dd3b0a2b8cc83e8227cb9289dc435
|
|
| MD5 |
901333a2af6a6a533ef002c3f4aa847a
|
|
| BLAKE2b-256 |
b6be3622d9d511da8e5e7d524f62689933c1ebea1be1845debda3aff1aaaa767
|
File details
Details for the file hh_c2t-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hh_c2t-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8411574a5fc3ccd6cad102670b983706ada2b19475c03dca0128963049f94424
|
|
| MD5 |
05ae5234e784cf8b9ecdc53f3dde57f8
|
|
| BLAKE2b-256 |
e1bf8aa5318715040ceab7986bef62fdae2d017954f30d8d4910a14452a94b76
|