lima icon indicating copy to clipboard operation
lima copied to clipboard

Is it possible to share clipboard with host?

Open euforic opened this issue 4 years ago • 11 comments

Currently I am trying to share the system clipboard between host and vm to allow for easier copy and pasting.

euforic avatar Nov 18 '21 23:11 euforic

Clipboard of what?

AkihiroSuda avatar Nov 19 '21 05:11 AkihiroSuda

An example would be if I copied something from vim (in vm) then wanted to paste into safari (on my Mac). For qemu ui based vms they usually leverage Spice tools for this.

euforic avatar Nov 19 '21 07:11 euforic

Are you using something other than the regular terminal application, to access your limactl shell ?

afbjorklund avatar Nov 19 '21 17:11 afbjorklund

Nope just iterm2 and then directly into lima shell

euforic avatar Nov 19 '21 17:11 euforic

I was thinking that it would have the usual "select text" and copy/paste functions, but am missing something...

https://iterm2.com/features.html

afbjorklund avatar Nov 19 '21 17:11 afbjorklund

I was thinking that it would have the usual "select text" and copy/paste functions, but am missing something...

It does, and it works fine if you use iTerm copy/paste functionality.

@euforic Are you using vim commands to copy into the clipboard? That will not work because the Linux vim is not connected to the macOS clipboard. But if you select the text using iTerm and copy via ⌘C, then it works fine.

jandubois avatar Nov 19 '21 17:11 jandubois

OSC 52

This plugin looked interesting: https://github.com/ojroques/vim-oscyank

anders@lima-default:~$ more .vimrc 
call plug#begin()
Plug 'ojroques/vim-oscyank'
call plug#end()
anders@lima-default:~$ vim --version | head -1
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Nov 08 2021 14:17:01)

:PlugInstall (https://github.com/junegunn/vim-plug/wiki/tutorial)

:OSCYank

But still controversial: https://gitlab.gnome.org/GNOME/vte/-/issues/2495

Did work in "kitty", but does not work in GNOME Terminal (default settings).

afbjorklund avatar Nov 19 '21 17:11 afbjorklund

I will dig a little deeper into my config make sure its not something on my end. Thank you for the help 🤙🏽. Also thank you for this project it is awesome. All the work is truly appreciated 🙏🏼

euforic avatar Nov 19 '21 17:11 euforic

I was thinking that it would have the usual "select text" and copy/paste functions, but am missing something...

It does, and it works fine if you use iTerm copy/paste functionality.

@euforic Are you using vim commands to copy into the clipboard? That will not work because the Linux vim is not connected to the macOS clipboard. But if you select the text using iTerm and copy via ⌘C, then it works fine.

Yeah I am using the system clipboard and was trying to bridge the linux system clipboard with the Mac OS system clipboard similar to how UTM does it with the Spice tools

euforic avatar Nov 19 '21 18:11 euforic

https://iterm2.com/documentation-utilities.html - see it2copy

Copies text to the pasteboard. Works over ssh. Accepts either standard input or a named file.

afbjorklund avatar Nov 19 '21 18:11 afbjorklund

It turns out (and TIL), sharing clipboard isn't a straight forward thing to make it happen (at least via SSH, X11 forwarding seems to be the promising way to do so though). So I was able to make it work via that way.

This requires installing XQuartz and X11 forwarding (which is described in the gist) and I chose to SSH to lima guest via ssh (but this requires additional authentication setup - like adding public key to authorized_keys on lima) instead of lima since that's the way I know at the moment. But lima configuration yaml also seems to support ssh configuration there, so you might get lucky with that.

Although it's not an auto magic way that lima just comes with, but I'm quite satisfied with the way it works at the moment.

ryuheechul avatar Apr 06 '22 04:04 ryuheechul