lima-vm / lima

Linux virtual machines, with a focus on running containers
https://lima-vm.io/
Apache License 2.0
15.18k stars 596 forks source link

Is it possible to share clipboard with host? #424

Open euforic opened 2 years ago

euforic commented 2 years ago

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

AkihiroSuda commented 2 years ago

Clipboard of what?

euforic commented 2 years ago

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.

afbjorklund commented 2 years ago

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

euforic commented 2 years ago

Nope just iterm2 and then directly into lima shell

afbjorklund commented 2 years ago

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

https://iterm2.com/features.html

jandubois commented 2 years ago

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.

afbjorklund commented 2 years ago

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).

euforic commented 2 years ago

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 commented 2 years ago

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

afbjorklund commented 2 years ago

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

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

ryuheechul commented 2 years ago

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.