gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

feat(cli): Support wl-clipboard for wayland

Open xcpky opened this issue 2 months ago • 10 comments

TLDR

As documented, /copy uses xsel or xclip under the hood. They only works on X11. This PR uses wl-copy for wayland session.

Dive Deeper

Reviewer Test Plan

  1. Run Linux with wayland compositor.
  2. install wl-clipboard
  3. try /copy

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Closes #11505

xcpky avatar Oct 20 '25 15:10 xcpky

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

google-cla[bot] avatar Oct 20 '25 15:10 google-cla[bot]

Summary of Changes

Hello @xcpky, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the /copy command's compatibility on Linux by introducing native support for Wayland display servers. Previously limited to X11 environments, the command can now seamlessly handle clipboard operations in Wayland sessions, ensuring a more consistent user experience across different Linux desktop setups.

Highlights

  • Wayland Clipboard Support: The CLI's /copy command now supports Wayland display servers on Linux by integrating wl-clipboard.
  • Session Type Detection: The copyToClipboard utility function has been updated to detect the XDG_SESSION_TYPE environment variable to determine if the current session is Wayland, and then use wl-copy accordingly.
  • Improved Error Handling: Specific error handling has been added for cases where wl-copy is not found, providing a clear message to the user to install wl-clipboard.
  • Documentation Update: The docs/cli/commands.md file has been updated to inform users that wl-clipboard is required for the /copy command on Wayland sessions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot] avatar Oct 20 '25 15:10 gemini-code-assist[bot]

Hi @xcpky,

I've been testing the PR for my own needs and noticed a few issues with the Wayland clipboard implementation and its tests. I've made some fixes and added more comprehensive tests to ensure it works correctly across X11 and Wayland environments.

Specifically, I've addressed:

  • A TypeScript error related to process.env.XDG_SESSION_TYPE access.
  • Refactored the clipboard tests in commandUtils.test.ts to accurately reflect wl-copy behavior on Wayland and xclip/xsel on X11, including correct error handling.

I've pushed these changes to my fork on the support-wayland-jk branch. You can review them here: https://github.com/jk-kashe/gemini-cli/tree/support-wayland-jk .

Would you be able to incorporate these fixes into your PR? Alternatively, if you're open to it, I'd be happy to contribute directly to your branch.

Please let me know what works best for you.

Thanks again!

jk-kashe avatar Oct 22 '25 11:10 jk-kashe

Hi @xcpky,

I've been testing the PR for my own needs and noticed a few issues with the Wayland clipboard implementation and its tests. I've made some fixes and added more comprehensive tests to ensure it works correctly across X11 and Wayland environments.

Specifically, I've addressed:

* A TypeScript error related to `process.env.XDG_SESSION_TYPE` access.

* Refactored the clipboard tests in `commandUtils.test.ts` to accurately reflect `wl-copy` behavior on Wayland and `xclip`/`xsel` on X11, including correct error handling.

I've pushed these changes to my fork on the support-wayland-jk branch. You can review them here: https://github.com/jk-kashe/gemini-cli/tree/support-wayland-jk .

Would you be able to incorporate these fixes into your PR? Alternatively, if you're open to it, I'd be happy to contribute directly to your branch.

Please let me know what works best for you.

Thanks again!

Hi. Thank you for bringing me the issues you met. Indeed somehow I didn't upload the fix for process.env.XDG_SESSION_TYPE. For the test I leave it not implemented because I don't have time and not familiar with js/ts tests. I am not sure your test implementation is correct, I just gave it a glance and found that it tests xsel fallback for wl-clipboard, which simply doesn't happen with my commit.

xcpky avatar Oct 22 '25 12:10 xcpky

Did this pull request end up going anywhere? Started following the thread recently and was wondering if you all need some help on this? Would really like to see this implemented in the CLI, especially beacause GNOME is now fully on wayland, and a lot of linux distros are going wayland-only, meaning gemini-cli will essentially not have a copy functionality for users on more recent distributions! Again, let me know how I can help.

FIREBAT-66 avatar Nov 15 '25 14:11 FIREBAT-66

Did this pull request end up going anywhere? Started following the thread recently and was wondering if you all need some help on this?

The PR works already, but it lacks test code. I don't want to spend time on that.

xcpky avatar Nov 19 '25 16:11 xcpky

@scidomino is now our resident expert on keyboard and clipboard support. I think this is worth landing even if we have to manually add the tests. Fingers crossed that Gemini 3.0 makes adding the tests a lot less painful than it would be in 2.5

jacob314 avatar Dec 03 '25 18:12 jacob314

We can't approve this until the @xcpky signs the cla. Thanks!

scidomino avatar Dec 03 '25 18:12 scidomino

Did this pull request end up going anywhere? Started following the thread recently and was wondering if you all need some help on this?

The PR works already, but it lacks test code. I don't want to spend time on that.

Thank you @xcpky! How can I merge your PR with my local installation on my system?

FIREBAT-66 avatar Dec 04 '25 18:12 FIREBAT-66

I have signed cla. But I found there are conflicts. It seems gemini-cli is using clipboardy, which supports wayland. So I guess the latest gemini cli already works with wayland? I don't use gemini-cli recently so I don't know.

xcpky avatar Dec 05 '25 05:12 xcpky

ok. If that's the case then it sounds like this is not longer needed. Feel free to open another PR in the future if you think changes are warranted. Thanks!

scidomino avatar Dec 05 '25 16:12 scidomino