From 868a29a8a7a404ee1681fdbf84d969795447dcbb Mon Sep 17 00:00:00 2001 From: Priban Date: Wed, 26 Feb 2025 18:09:06 +0100 Subject: [PATCH] mac support --- README.md | 6 ++++-- src/ctxify/main.py | 29 +++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index df5f0ac..3e85c53 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,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. ✨ --- @@ -51,10 +51,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 9fee5f9..c6961a2 100644 --- a/src/ctxify/main.py +++ b/src/ctxify/main.py @@ -3,6 +3,7 @@ from pathlib import Path 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 = { @@ -106,17 +107,33 @@ def get_git_files(root_dir, include_md=False): def copy_to_clipboard(text): - """Copy text to system clipboard using xclip""" + """Copy text to system clipboard using pbcopy (macOS) or xclip (Linux)""" + system = platform.system().lower() + print("Deciding") try: - subprocess.run( - ['xclip', '-selection', 'clipboard'], input=text.encode('utf-8'), check=True - ) + if system == 'darwin': # macOS + print("Darwin") + subprocess.run( + ['pbcopy'], input=text.encode('utf-8'), check=True + ) + elif system == 'linux': # Linux + print("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