Skip to content

Fix: Linux clipboard fallback skips xsel when xclip is not installed#4

Open
TofuGG wants to merge 1 commit into
phlx0:mainfrom
TofuGG:something
Open

Fix: Linux clipboard fallback skips xsel when xclip is not installed#4
TofuGG wants to merge 1 commit into
phlx0:mainfrom
TofuGG:something

Conversation

@TofuGG

@TofuGG TofuGG commented Jun 6, 2026

Copy link
Copy Markdown

What does this PR do?

On Linux, copy_to_clipboard() tried xclip and xsel as fallbacks inside a single shared try/except block. If xclip wasn't installed, the FileNotFoundError it raised escaped the loop and was caught by the outer handler — meaning xsel was never tried. Users with xsel but not xclip (common on Debian/Ubuntu) would silently fail to copy even though a working tool was present.

The fix wraps each command in its own try/except inside the loop, so a missing tool just continues to the next candidate. The macOS and Windows branches are also given their own try/except blocks for the same reason.

Three regression tests are added covering: xsel succeeding when xclip is absent, xclip succeeding when xsel is absent, and False returned cleanly when neither tool is installed.

Related issue

No related issue.

Checklist

  • Tests pass (make test)
  • New behaviour is covered by tests (if applicable)
  • CHANGELOG.md updated under [Unreleased]
## [Unreleased]

### Fixed
- Clipboard fallback on Linux now correctly tries `xsel` when `xclip` is not
  installed. Previously both commands shared a single `try/except`, so a
  `FileNotFoundError` from `xclip` aborted the loop before `xsel` was ever
  attempted.

Refactor clipboard handling for better error management and support for Linux commands.
@phlx0

phlx0 commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Sorry for the slow review on this one, it sat in my queue longer than it should have. Thanks for your patience, and thanks for the clear write-up of the root cause. The diagnosis is right and the fix is the correct shape. A few things before I can merge:

1. Commit message

Please reword Improve clipboard functionality with error handling to follow Conventional Commits, and to actually describe the fix. Something like:

fix(clipboard): try xsel when xclip is not installed on Linux

2. Checklist vs. diff

The description says three regression tests were added and that CHANGELOG.md is updated under [Unreleased], and all three boxes are ticked, but the diff is one file (snip/utils/clipboard.py, +26 −13). No tests, no changelog entry. Could you push those? The changelog text in the PR body looks good, it just needs to land in the file.

Once the commit message and the tests plus changelog are in, this is good to go. Thanks!

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