Live data from Hacker News

Yank: Yank Terminal Output to Clipboard

github.com

31–40 of 57 posts

Re: Yank: Yank Terminal Output to Clipboard

#31
post #9

Earlier quoted context omitted.

> The only place I've seen the word "yank" in computing is in Emacs context, where it means "paste", not "copy"... This is a confusing difference between Emacs and Vim. Emacs uses it for pasting, Vim uses it for copying.

How did the Emacs developers ever thought "yank" would convey the meaning of "paste"? (Legitimate question. I'm aware some UX faux-pas do happen, but I don't see how)

Oh oh. Someone had a too harmonic day and wants to add some spice to it.

Re: Yank: Yank Terminal Output to Clipboard

#32

Useful tool indeed, thanks for sharing. I use clipper[1], which delivers a similar function through a different implementation. What I like about that one is that with right config you can also pipe output from remote servers back into your machine's clipboard, which is quite handy in so many situations. [1] https://github.com/wincent/clipper

There's a better way to do it. Terminals have a special escape sequence called OSC 52, which allows you to insert into the clipboard from even remote SSH sessions. Try this:

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

Re: Yank: Yank Terminal Output to Clipboard

#33
post #25

Earlier quoted context omitted.

That works outside WSL2, not inside, right?

clip.exe works to and from WSL 2. But if you run VcXsrv you can use the native Linux clipboard and have it shared between WSL 2 and Windows. This is what I do because then tools like Vim, the pass utility and other command line tools can write to and read from the native Linux clipboard and everything will work out of the box. If you wanted to reproduce pbcopy / pbpaste in native Linux or WSL 2 you can set up aliases…

Oh that’s neat. Do you use the x server for just this purpose or do you also run linux gui apps? I’ve been thinking about investing more into it but the high dpi stuff does not work properly.

Re: Yank: Yank Terminal Output to Clipboard

#34

This is actually a solution to a problem I've been looking at recently. My current experimental answer is using the terminal within Neovim, which is kind of a superset of this in some ways. I'm wondering if there's a standard way to invoke vim and just get a selection. Might make a good analog for vim users who don't want to commit to using its terminal.

In iTerm, searching for the text selects it, and you can use tab to expand the selection. Not quite vim, but it’s better than many other terminal emulators in that space.

Re: Yank: Yank Terminal Output to Clipboard

#35
I've been using ubuntu for over a decade and I have no idea how the clipboard works.

There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want.

I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it.

Can someone finally explain it to me? Or tell me what to do to make it sane.

(it of course did occur to me to google the question over the past 10 years but every time I did, I didn't find a satisfactory answer for something that ought to be a basic computer literacy skill)

Re: Yank: Yank Terminal Output to Clipboard

#36
post #35

I've been using ubuntu for over a decade and I have no idea how the clipboard works. There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want. I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it. Can someone finally explain it to…

In most terminal emulators you can use ctrl+shift+c/v to copy/paste to and from the clipboard. Works with vim to.

Re: Yank: Yank Terminal Output to Clipboard

#37
post #35

I've been using ubuntu for over a decade and I have no idea how the clipboard works. There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want. I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it. Can someone finally explain it to…

Clipboards in x11 are based on selections. There are two selections of note, the primary selection and clipboard selection. In GUI applications, selecting text copies it to the primary selection, middle clicking pastes the primary selection. Ctrl-C copies to the clipboard selection, Ctrl-V pastes the clipboard selection. The happy path is to stick to those operations only.

For terminals, ctrl-c/Ctrl-v have conflicting interpretations so are usually bound to ctrl-shift-c/ctrl-shift-v. Some (e.g. iterm) try to emulate copy on select on operating systems that don't support it by copying the selection to the single clipboard.

For vim, the selections are bound to buffers. * Is the primary/selection buffer, + is the clipboard. Use "+y/"+p for ctrl-c/ctrl-v equivalents, or "*y/"*p for copy-on-select/middle click equivalents. Note that some distros ship a default "vim-minimal"/"vim-tiny" package built without this support so they can use it as "vi" for POSIX compatibility without pulling in x11 libraries. In that case look for a "vim-x11", "vim-full" or "gvim" package. Or use neovim, I haven't seen packagers slice that up the same way. Depending on your terminal, you may be also able to use the GUI equivalents in insert mode anyway (don't try use your terminal paste in normal mode, it'll paste into the command buffer).

Shift-Insert is unfortunately application dependent. I think it _should_ be equivalent to middle click, but some apps treat it as ctrl-v.

Some clipboard managers or applications will overwrite the primary contents with the clipboard contents when you perform an explicit copy.

Re: Yank: Yank Terminal Output to Clipboard

#38
post #35

I've been using ubuntu for over a decade and I have no idea how the clipboard works. There seems to be multiple clipboards and I have no idea when I am using which. I generally spam some combination of ctrl-v, shift-insert, rightclick context menu paste, middleclick, etc until I get what I want. I've abandoned vim for a gui solely because I have no idea how to copy stuff to/from it. Can someone finally explain it to…

clipboard = regular C-c and C-v stuff

primary = highlight / middle click

vim has its own used by default when you dd, p, etc. You can copy to one of the previous things (assuming your build enabled it) with "+y and "*y key sequences. You can also paste the same way, but I usually just let the term emu handle that with ctrl-shift-v or similar.

shift-insert is kinda weird actually. AFAIK it should paste from selection, but it often surprises me, so I avoid it.

edit: s/selection/primary/

Re: Yank: Yank Terminal Output to Clipboard

#39
post #9

Earlier quoted context omitted.

> The only place I've seen the word "yank" in computing is in Emacs context, where it means "paste", not "copy"... This is a confusing difference between Emacs and Vim. Emacs uses it for pasting, Vim uses it for copying.

How did the Emacs developers ever thought "yank" would convey the meaning of "paste"? (Legitimate question. I'm aware some UX faux-pas do happen, but I don't see how)

Emacs developers viewed it as yanking out of the buffer into the document. Vim viewed it as yanking out of the document into the buffer. It's poor terminology either way, as yanking to me implies moving rather than copying as in both applications

Re: Yank: Yank Terminal Output to Clipboard

#40

On Mac OS, a much less powerful but built in tool is `pbcopy`.

To replicate pbcoby on X11 systems, add to your bashrc: alias clip="xclip -selection clipboard" `echo hello | clip` will copy 'hello' to the clipboard, and similarly `ls | clip` will copy a bunch of lines to the clipboard. You might need to install xclip through your package manger (the package is just named xclip on Arch).

On Wayland there's wl-clipboard (with wl-copy and wl-paste commands) which works basically the same.
Post reply on HN