Skip to content

Commit

Permalink
Merge pull request #9 from NicoJorgensen1/linux_support
Browse files Browse the repository at this point in the history
added support for linux using xclip and pyperclip
  • Loading branch information
kasperjunge authored Oct 21, 2024
2 parents 4399b83 + a0f6d2b commit b2e7e3d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ This format provides a clear overview of your project structure followed by the

## Note

This tool is designed for macOS and Windows.
This tool is designed for macOS and Windows. \
**Update**: Now also available on Linux, if xclip (or similar package) is installed. Install using `$ sudo apt install xclip`

## Development

Expand Down
8 changes: 6 additions & 2 deletions copcon/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import platform
import sys
import pathspec
import pyperclip

app = typer.Typer()

Expand Down Expand Up @@ -153,6 +154,8 @@ def get_file_content(file_path: Path) -> str:

def copy_to_clipboard(text: str):
system = platform.system()

# pyperclip should be OS-agnostic, but as I don't have neither Windows or MacOS available, I cannot test it, hence keep the original code for MacOS and Windows
if system == "Darwin": # macOS
process = subprocess.Popen(
"pbcopy", env={"LANG": "en_US.UTF-8"}, stdin=subprocess.PIPE
Expand All @@ -166,8 +169,9 @@ def copy_to_clipboard(text: str):
win32clipboard.SetClipboardText(text, win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()
else:
print(f"Clipboard functionality not supported on {system}")
sys.exit(1)
pyperclip.copy(text)
# print(f"Clipboard functionality not supported on {system}")
# sys.exit(1)


@app.command()
Expand Down
12 changes: 11 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python = "^3.11"
typer = "^0.12.3"
pywin32 = {version = "^300", platform = "win32"}
pathspec = "^0.12.1"
pyperclip = "^1.8.2"

[tool.poetry.scripts]
copcon = "copcon:copcon_app"
Expand Down

0 comments on commit b2e7e3d

Please sign in to comment.