Skip to content

fix(clipboard): fall back to xclip when clip.exe is unreachable on Linux#84

Merged
aadya940 merged 1 commit intomasterfrom
fix/clipboard-docker-on-windows
May 1, 2026
Merged

fix(clipboard): fall back to xclip when clip.exe is unreachable on Linux#84
aadya940 merged 1 commit intomasterfrom
fix/clipboard-docker-on-windows

Conversation

@aadya940
Copy link
Copy Markdown
Owner

@aadya940 aadya940 commented May 1, 2026

Summary

  • pyperclip misidentifies Docker-on-Windows containers as WSL because /proc/version contains "microsoft", then unconditionally tries clip.exe — which doesn't exist inside the container
  • clipboard_set and clipboard_get both fail with FileNotFoundError: clip.exe
  • Fix: check if clip.exe is actually reachable via shutil.which before using the WSL code path; if absent but xclip is installed, use xclip directly
  • All other platforms (Windows, macOS, real WSL where clip.exe exists) fall through to pyperclip unchanged

Test plan

  • On Windows: clipboard_set/clipboard_get still work via pyperclip
  • On macOS: unchanged, pyperclip handles it
  • On real WSL (clip.exe reachable): unchanged, pyperclip handles it
  • On Linux / Docker-on-Windows with xclip installed: uses xclip, works correctly
  • On Linux without xclip: falls back to pyperclip (which will surface a clear error)

🤖 Generated with Claude Code

pyperclip detects Docker-on-Windows containers as WSL because /proc/version
contains "microsoft", then unconditionally tries clip.exe which doesn't exist
in the container. This causes clipboard_set/clipboard_get to fail entirely.

Fix: check whether clip.exe is actually reachable via shutil.which before
deciding to use the WSL code path. If clip.exe is absent but xclip is
installed, use xclip directly. All other platforms (Windows, macOS, real WSL)
fall through to pyperclip as before.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 1, 2026 05:01
@aadya940 aadya940 merged commit a92bddd into master May 1, 2026
2 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Linux fallback path for clipboard operations to avoid pyperclip mis-detecting certain Docker-on-Windows containers as WSL and attempting to call an unavailable clip.exe.

Changes:

  • Added helper detection functions to decide between pyperclip and xclip.
  • Implemented xclip-based copy/paste helpers and routed clipboard_get/clipboard_set through them when selected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread orbit/_tools/clipboard.py
Comment on lines +16 to +25
def _use_xclip() -> bool:
"""
Returns True when we should use xclip instead of pyperclip.

pyperclip detects Docker-on-Windows containers as WSL (because /proc/version
contains "microsoft") and tries clip.exe — which doesn't exist in the container.
We only use xclip when clip.exe is genuinely unreachable and xclip is installed.
On real WSL, Windows, or macOS this returns False and pyperclip handles it as normal.
"""
return not _clip_exe_available() and _xclip_available()
Comment thread orbit/_tools/clipboard.py
Comment on lines +16 to +25
def _use_xclip() -> bool:
"""
Returns True when we should use xclip instead of pyperclip.

pyperclip detects Docker-on-Windows containers as WSL (because /proc/version
contains "microsoft") and tries clip.exe — which doesn't exist in the container.
We only use xclip when clip.exe is genuinely unreachable and xclip is installed.
On real WSL, Windows, or macOS this returns False and pyperclip handles it as normal.
"""
return not _clip_exe_available() and _xclip_available()
Comment thread orbit/_tools/clipboard.py
Comment on lines +29 to +33
result = subprocess.run(
["xclip", "-selection", "clipboard"],
input=text.encode("utf-8"),
capture_output=True,
)
Comment thread orbit/_tools/clipboard.py
Comment on lines +41 to +44
result = subprocess.run(
["xclip", "-selection", "clipboard", "-o"],
capture_output=True,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants