diff --git a/dumpy.py b/dumpy.py index 40a449c..905c266 100644 --- a/dumpy.py +++ b/dumpy.py @@ -2,18 +2,22 @@ from pathlib import Path import pathspec import argparse import mimetypes +import pyperclip def get_file_description(path: Path): mime_type, _ = mimetypes.guess_type(path) return mime_type or "Unknown mimetype" -def output_metadata(path: Path, root: Path): +def generate_metadata_string(path: Path, root: Path) -> list[str]: desc = get_file_description(path) relative_path = path.relative_to(root) - print("#################") - print(f"## Filename: {relative_path}") - print(f"## Mimetype: {desc}") - print("#################") + return_data = [] + return_data.append("#################") + return_data.append(f"## Filename: {relative_path}") + return_data.append(f"## Mimetype: {desc}") + return_data.append("#################") + + return return_data def get_ignore_spec(root: Path): gitignore_path = root / ".gitignore" @@ -32,24 +36,27 @@ def should_include(path: Path, spec: pathspec.PathSpec | None, root: Path, inclu return not spec.match_file(str(relative_path)) -def walk_filesystem(ignore_gitignore: bool, include_git_dir: bool = False): +def walk_filesystem(ignore_gitignore: bool, include_git_dir: bool = False) -> list[str]: root = Path(".") spec = None if not ignore_gitignore: spec = get_ignore_spec(root) + final_content: list[str] = [] + for path in root.rglob("*"): if path.is_file(): # print the filename (for now) if should_include(path, spec, root, include_git_dir): - output_metadata(path, root) + final_content += generate_metadata_string(path, root) success, content = get_file_contents(path) if success: - print("## File Contents:") - print(content) - print("\n") - + final_content.append("## File Contents:\n```") + final_content.append(content) + final_content.append("```\n") + return final_content + def get_file_contents(path: Path) -> tuple[bool, str]: try: @@ -74,9 +81,26 @@ def main(): help="Include the .git directory in the output" ) - args = parser.parse_args() + parser.add_argument( + "--no-clipboard", + action="store_true", + help="Skip putting content into the clipboard and ouput directly to the console" + ) - walk_filesystem(ignore_gitignore=args.no_gitignore) + args = parser.parse_args() + content: list[str] = [] + + content.append(f"Root Directory: {Path(".").absolute()}\n") + + content = walk_filesystem(ignore_gitignore=args.no_gitignore) + + if args.no_clipboard: + print("\n".join(content)) + else: + pyperclip.copy("\n".join(content)) + + if not content: + return if __name__ == "__main__": main() diff --git a/pyproject.toml b/pyproject.toml index 4c37e01..963d86a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,4 +6,5 @@ readme = "README.md" requires-python = ">=3.14" dependencies = [ "pathspec>=1.0.3", + "pyperclip>=1.11.0", ] diff --git a/uv.lock b/uv.lock index b0b71bb..85fb89f 100644 --- a/uv.lock +++ b/uv.lock @@ -8,10 +8,14 @@ version = "0.1.0" source = { virtual = "." } dependencies = [ { name = "pathspec" }, + { name = "pyperclip" }, ] [package.metadata] -requires-dist = [{ name = "pathspec", specifier = ">=1.0.3" }] +requires-dist = [ + { name = "pathspec", specifier = ">=1.0.3" }, + { name = "pyperclip", specifier = ">=1.11.0" }, +] [[package]] name = "pathspec" @@ -21,3 +25,12 @@ sdist = { url = "https://files.pythonhosted.org/packages/4c/b2/bb8e495d5262bfec4 wheels = [ { url = "https://files.pythonhosted.org/packages/32/2b/121e912bd60eebd623f873fd090de0e84f322972ab25a7f9044c056804ed/pathspec-1.0.3-py3-none-any.whl", hash = "sha256:e80767021c1cc524aa3fb14bedda9c34406591343cc42797b386ce7b9354fb6c", size = 55021, upload-time = "2026-01-09T15:46:44.652Z" }, ] + +[[package]] +name = "pyperclip" +version = "1.11.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e8/52/d87eba7cb129b81563019d1679026e7a112ef76855d6159d24754dbd2a51/pyperclip-1.11.0.tar.gz", hash = "sha256:244035963e4428530d9e3a6101a1ef97209c6825edab1567beac148ccc1db1b6", size = 12185, upload-time = "2025-09-26T14:40:37.245Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/df/80/fc9d01d5ed37ba4c42ca2b55b4339ae6e200b456be3a1aaddf4a9fa99b8c/pyperclip-1.11.0-py3-none-any.whl", hash = "sha256:299403e9ff44581cb9ba2ffeed69c7aa96a008622ad0c46cb575ca75b5b84273", size = 11063, upload-time = "2025-09-26T14:40:36.069Z" }, +]