diff --git a/README.md b/README.md index 68b2ad6..d2e6991 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Ever wanted to: - Get just the structure without the contents? - Know how many tokens your project weighs in at? -`ctxify` does it all. It’s lightweight, fast, and skips the fluff (like lock files or `.gitignore`). Built with Python 3.13 and Git magic. ✨ +`ctxify` does it all. It's lightweight, fast, and skips the fluff (like lock files or `.gitignore`). Built with Python 3.13 and Git magic. ✨ --- @@ -54,10 +54,12 @@ On Linux, install `xclip`: sudo apt install xclip ``` +On macOS, clipboard support is built-in (uses `pbcopy`), so no additional installation is needed. + --- ## Usage -Run it from your Git repo’s root: +Run it from your Git repo's root: ```bash ctxify diff --git a/src/ctxify/main.py b/src/ctxify/main.py index e56cb4f..94f01d5 100644 --- a/src/ctxify/main.py +++ b/src/ctxify/main.py @@ -5,6 +5,7 @@ from prompt_toolkit import PromptSession from prompt_toolkit.completion import FuzzyWordCompleter +import platform # Files/extensions to skip (non-code files) for content inclusion NON_CODE_PATTERNS = { @@ -133,17 +134,30 @@ def get_git_files( def copy_to_clipboard(text: str) -> bool: - """Copy text to system clipboard using xclip""" + """Copy text to system clipboard using pbcopy (macOS) or xclip (Linux)""" + system = platform.system().lower() try: - subprocess.run( - ['xclip', '-selection', 'clipboard'], input=text.encode('utf-8'), check=True - ) + if system == 'darwin': # macOS + subprocess.run( + ['pbcopy'], input=text.encode('utf-8'), check=True + ) + elif system == 'linux': # Linux + subprocess.run( + ['xclip', '-selection', 'clipboard'], input=text.encode('utf-8'), check=True + ) + else: + print(f'Warning: Clipboard operations not supported on {platform.system()}') + return False return True except subprocess.CalledProcessError: - print('Warning: Failed to copy to clipboard (xclip error)') + cmd = 'pbcopy' if system == 'darwin' else 'xclip' + print(f'Warning: Failed to copy to clipboard ({cmd} error)') return False except FileNotFoundError: - print("Warning: xclip not installed. Install it with 'sudo apt install xclip'") + if system == 'darwin': + print("Warning: pbcopy not found. This is unexpected as it should be built into macOS") + else: + print("Warning: xclip not installed. Install it with 'sudo apt install xclip'") return False