Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get clipboard sharing working with tmux #782

Closed
spinningarrow opened this issue Aug 1, 2018 · 32 comments
Closed

Unable to get clipboard sharing working with tmux #782

spinningarrow opened this issue Aug 1, 2018 · 32 comments

Comments

@spinningarrow
Copy link

I'm unable to get clipboard sharing with tmux working properly. I have this setting in my kitty.conf:

clipboard_control write-clipboard write-primary

When I select text in tmux's copy mode, it does not seem to get written to the system clipboard - when I paste using Cmd+V, the text copied in tmux does not get pasted.

I also tried it with clipboard_control read-clipboard write-clipboard read-primary write-primary but that did not help.

This works in iTerm when the "Applications in terminal may access clipboard" setting is turned on - is it something that is supported in kitty too?

I'm using macOS with kitty version 0.11.3.

@kovidgoyal
Copy link
Owner

You need to tell tmux to turn it on in the tmux settings.

@spinningarrow
Copy link
Author

spinningarrow commented Aug 1, 2018

Hmm, I didn't have to do this with iTerm - do you know which tmux setting it is?

EDIT: I ran tmux show-options -g -s set-clipboard which returned set-clipboard external, but it still does not work with kitty. Am I missing something?

@kovidgoyal
Copy link
Owner

I have no idea, I'm not a tmux user (IMO tmux is a horrible pile of hacks). All I can tell you is that OSC 52 works with kitty, which you can test by doing

printf "\033]52;c;$(printf "%s" "blabla" | base64)\a"

and your clipboard will contain the string blaba

@spinningarrow
Copy link
Author

I see - thanks, I'll dig in a bit.

IMO tmux is a horrible pile of hacks

I find it quite nice, but have no strong preference - what alternative would you recommend?

@kovidgoyal
Copy link
Owner

I personally dont use a multiplexer at all. kitty itself has pretty much all the functionality of a multiplexer builtin, with the exception of remote persistence see #391

Oh and by the way, you can also use the clipboard kitten to more easily copy stuff to the keyboard, which uses OSC 52 under the hood

kitty +kitten clipboard --help

@IngoMeyer441
Copy link

tmux resends OSC 52 to the outer terminal without the c parameter, like executing:

printf "\033]52;;$(printf "%s" "blabla" | base64)\a"

in kitty directly. kitty does not accept an empty clipboard parameter (which is allowed in the XTerm specs). Would it be possible to add support for empty clipboard paramters? It would make tmux users happy 😄 .

kovidgoyal added a commit that referenced this issue Nov 21, 2018
…parameter

This is apparently used by tmux. See #782
@kovidgoyal
Copy link
Owner

sure, done

@IngoMeyer441
Copy link

Great, thanks! 👍

@gitaarik
Copy link

So, should this work now? I tried it but to no avail. I've set in my kitty.conf:

clipboard_control write-clipboard write-primary

And tried to execute this inside tmux:

echo test | kitty +kitten clipboard

But it doesn't end up in my system clipboard. It does outside tmux. I'm using kitty 0.13.3.

@kovidgoyal
Copy link
Owner

No idea. All I did was get kitty to accept without the c parameter, as described by @IngoHeimbach

@gitaarik
Copy link

I found an alternative solution though, in case anyone is interested:
https://github.com/tmux-plugins/tmux-yank

@IngoMeyer441
Copy link

IngoMeyer441 commented Mar 21, 2019

I have set

set -g set-clipboard on

in my .tmux.conf. When selecting text in tmux copy mode, tmux sends the text to the outer teminal with a OSC52 terminal sequence and kitty puts the text into the system clipboard.
But I don't know how

kitty +kitten clipboard

works internally. I think this command is not needed within tmux.

@kovidgoyal
Copy link
Owner

The clipboard kitten probably does not work because while tmux generates OSC 52 itself when copying, it does not pass it through when the program running inside it generates it.

@IngoMeyer441
Copy link

IngoMeyer441 commented Mar 21, 2019

Programs generating OSC52 should also work. I use a script that generates OSC52 for yanking text from vim to the system clipboard.

@kovidgoyal
Copy link
Owner

Well the clipboard kitten is just an easy to use API for generating OSC
52

@IngoMeyer441
Copy link

Ok, I tried

echo "test" | kitty +kitten clipboard

within tmux which runs in kitty. For me, it works.

@hillyu
Copy link

hillyu commented Apr 17, 2019

Not working for remote Tmux session.
Update: manually set osc52 sequence works, for now I managed to use a custom script to do so with Tmux. Something like:

printf "$esc" > $SSH_TTY

Also need git version that supports no-append as clipboard-option, otherwise it will only append to previous content.

I think Tmux's default osc52 may not be the compatible with kitty if it is running over SSH.

@IngoMeyer441
Copy link

@hillyu You are right, by default tmux does not pass OSC52 if nested in another tmux session. The reason is the set TERM variable. If you use only one tmux instance your outer terminal probably sets TERM to xterm*. For xterm compatible terminals tmux enables OSC52 out of the box (Ms entry in options-table.c). If you nest tmux, the nested tmux instance gets the TERM value which is set by the outer tmux instance (probably screen* or tmux*). To get OSC52 working you have to add a Ms entry to the terminal-overrides option. You can try to add

set -ga terminal-overrides "screen*:Ms=\\E]52;%p1%s;%p2%s\\007,tmux*:Ms=\\E]52;%p1%s;%p2%s\\007"

to your .tmux.conf to enable OSC52 for a nested tmux session.

@hillyu
Copy link

hillyu commented Apr 18, 2019

Thanks @IngoHeimbach , for pointing me to the right direction. I think the culprit for my setup is another override setting:
set -g terminal-overrides 'xterm*:smcup@:rmcup@'. If I enable this, tmux will not pass OSC52. However if I ssh to a remote server and launch tmux on that server, everything works. I don't usually nest tmux, but will test out using Ms entry override.

@bastikempken
Copy link

@IngoHeimbach i've got the issue that the copy content of tmux is always appended to the clipboard. The "no-append" option of the kitty "clipboard_control" config seems to be ignored. Any idea? Thx

@IngoMeyer441
Copy link

@bastikempken I have tested the no-append option with v0.14.1 and it works for me. Are you sure you have the latest version of kitty installed?

@zpv
Copy link

zpv commented Jun 17, 2019

I am having the same issue as @bastikempken
Copying within tmux seems to append it to the clipboard, and the no-append option does not help.

Does not occur in iTerm nor Alacritty. MacOS.

@Luflosi
Copy link
Contributor

Luflosi commented Jun 17, 2019

Which version of kitty are you using?

@zpv
Copy link

zpv commented Jun 17, 2019

@Luflosi The latest release from brew cask.

 ~ kitty -v
kitty 0.14.2 created by Kovid Goyal

@zpv
Copy link

zpv commented Jun 17, 2019

Screen Recording 2019-06-17 at 5 44 51 PM

clipboard-control left on default. (no-append did nothing)
copy_on_select is set to no (has no difference either way)

@kovidgoyal
Copy link
Owner

I also cannot replicate, with set-clipboard on in tmux conf and running kitty as:

kitty -o clipboard_control=write-clipboard\ write-primary\ no-append

running

printf "\033]52;c;$(printf "%s" "blabla" | base64)\a"

multiple times does not append to clipboard.

@zpv
Copy link

zpv commented Jun 18, 2019

I'm sorry, it was my mistake. I didn't actually test the no-append option after upgrading kitty.
Thank you 🙏

@jessebett
Copy link

@gitaarik can you clarify your solution. I have tmux-yank but it does not solve this for me. Nothing is shared with system clipboard.

@gitaarik
Copy link

gitaarik commented Jul 19, 2019

@jessebett it's an alternative solution, nothing to do with this thread. Better refer to the documentation or issues of tmux-yank if it's not working for you.

@Integralist
Copy link

This worked for me on macOS...

# ~/.tmux.conf

- bind-key -T copy-mode-vi 'y' send -X copy-pipe "reattach-to-user-namespace pbcopy"
+ bind-key -T copy-mode-vi 'y' send -X copy-pipe "kitty +kitten clipboard"

To fix the problem of kitty defaulting to appending to the clipboard (which seemed a strange default to set) I made the following modification...

# ~/.config/kitty/kitty.conf

clipboard_control write-clipboard write-primary no-append

@ahmedelgabri
Copy link

ahmedelgabri commented Sep 23, 2019

This worked for me on macOS...

# ~/.tmux.conf

- bind-key -T copy-mode-vi 'y' send -X copy-pipe "reattach-to-user-namespace pbcopy"
+ bind-key -T copy-mode-vi 'y' send -X copy-pipe "kitty +kitten clipboard"

To fix the problem of kitty defaulting to appending to the clipboard (which seemed a strange default to set) I made the following modification...

# ~/.config/kitty/kitty.conf

clipboard_control write-clipboard write-primary no-append

Maybe something like this would be better? So the behaviour is consistent whether you use Kitty or another terminal

bind-key -T copy-mode-vi y if-shell "test ! -z $KITTY_WINDOW_ID" "send-keys -X copy-pipe 'kitty +kitten clipboard'" "send-keys -X copy-pipe  'pbcopy'"

ahmedelgabri added a commit to ahmedelgabri/dotfiles that referenced this issue Sep 29, 2019
@kaka-ruto
Copy link

I found an alternative solution though, in case anyone is interested:
https://github.com/tmux-plugins/tmux-yank

Worked for me

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

No branches or pull requests