Skip to main content

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)
  • 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

  1. Collect Python files from a local directory:

    hh-c2t /path/to/project --extensions .py
    

    This collects all .py files in /path/to/project, respecting the hh-c2t-ignore file.

  2. Collect Python and text files from a Git repository:

    hh-c2t https://github.com/user/repo --extensions .py,.txt
    

    Clones the repository and collects .py and .txt files.

  3. Collect files from an SSH server:

    hh-c2t user@host /remote/path --password mypass --extensions .py
    

    Connects to the SSH server and collects .py files from /remote/path.

  4. Use a custom ignore file:

    hh-c2t /path/to/dir --ignore-file custom-ignore --extensions .md
    

    Collects .md files, ignoring patterns specified in custom-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:

  1. Fork the repository on GitHub.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Make your changes and commit (git commit -m "Add your feature").
  4. Push to your fork (git push origin feature/your-feature).
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hh_c2t-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

hh_c2t-0.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

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

Hashes for hh_c2t-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9a24e8151318a075502dc282fe6c5b01c31dd3b0a2b8cc83e8227cb9289dc435
MD5 901333a2af6a6a533ef002c3f4aa847a
BLAKE2b-256 b6be3622d9d511da8e5e7d524f62689933c1ebea1be1845debda3aff1aaaa767

See more details on using hashes here.

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

Hashes for hh_c2t-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8411574a5fc3ccd6cad102670b983706ada2b19475c03dca0128963049f94424
MD5 05ae5234e784cf8b9ecdc53f3dde57f8
BLAKE2b-256 e1bf8aa5318715040ceab7986bef62fdae2d017954f30d8d4910a14452a94b76

See more details on using hashes here.

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