Clipboard: Cut, copy, and paste anything, anywhere, all from the terminal
github.com
github.com
macOS (zsh/bash): command | pbcopy
windows (powershell) command | Set-Clipboard
https://git.sr.ht/~charles/dotfiles/tree/171c95a20394552e02a...
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
alias pbpaste='xclip -selection clipboard -o'
The special sauce is that you can put a server name from your ssh config on the end of a pbcopy or pbpaste command so you can do stuff like run `echo hello | pbcopy server2` on server1, after which doing `pbpaste` from server2 would print 'hello'. You can also do this in the other direction with pbpaste, eg from server2 you can run `pbpaste server1` and it'll print out the contents of server1's clipboard.
The current setup is a bit coupled to my rc files, but if there's interest would be glad to refactor a bit and toss it on github
Even just upload it in its current state would be nice :)
I'm doing some experimentation with something sort of along these lines via WebRTC.
Defaults with vi keys:
Leader+[: enter selection mode
Space: start selection
Return: copy selection
Leader+]: paste
If you enable mouse in tmux, you just select to copy.Then xsel -b / xclip -sel clip, or wl-clipboard for cli.
You could integrate it in vim as well but personally I like to keep that separate.
Overall it's much quicker - as yanking in vim with X11 forwarding and '+clipboard' sometimes had a delay.
(ps: I think OSC 52 is implemented in xterm and URXVT, but not yet in gnome-terminal)
That said, there are many great modern terminals to use. I suggest Alacritty.
Does it work on Cygwin (which has /dev/clipboard)?
But it is nice to have this tool with more functionality on all platforms in unified way!
I'm glad there are people not afraid to use the latest version of programming language features. I always try to use C++20 for new projects, but often the dependencies prevent me.
If you want to use the clipboard from cmdline you can also use
xclip (for Xorg)
wl-clipboard (for wayland)
and on macOS you can use the builtin commands: pbpaste pbcopy (see the man page)
These are what I’ve been using, but I might change now.
There's also xsel as a long time utility for Xorg as well.
All I was able to find was https://github.com/Slackadays/Clipboard/blob/6fd7e6b695ebe57... , which opens the X11 connection -- but where does it actually read/write the selection (clipboard)?
Clipboard does not have any configuration. Note that I said "have," not
"use." That's because Clipboard cleverly picks up on certain settings that
are present everywhere they're possibly used. One such setting is
NO_COLOR. NO_COLOR is an unofficial standard to specify a global disabling
of color output by software. If the NO_COLOR environment variable is
defined, then programs should not display color.
I'm unaware of many programs that actually respect $NO_COLOR. Certainly `ls` and `grep`, the two programs I use the most which display colored output, don't respect that environment variable. `ag` doesn't respect it either. In fact, the only program I use on a semi-regular basis which respects $NO_COLOR is `fd`. All the rest expect a `--no-color` command line parameter to disable colorized output. Given that, I'm wondering why the authors chose to control output colorization with an environment variable, rather than a command line argument.[1]: https://github.com/Slackadays/Clipboard/wiki/User-Experience...
alias grep='grep --color=auto'
alias ls='ls --color=auto'
Ls and grep are defined such that you can specify --color multiple times and the last one will take effect, allowing you to disable coloring while still using the alias that enables it. The FAQ at no-color.org states:> User-level configuration files and per-instance command-line arguments should override $NO_COLOR
So, it looks like like ls and grep respect it fine with just their default behaviour.
As an aside, at least on my system, ls and grep do not recognize --no-color. I need to specify it with --color=never.
I added the call to `ansifilter`:
function clip
if not tty >/dev/null
ansifilter | pbcopy
else
pbpaste
end
endxsel kind of works but I would like to copy paste anything
Tmux and GNU screen have their own copy buffers but they're not so useful when you're copying text from separate vim instances, scrolling both up and down in vim.
You're looking at it right now.
There's a number of clipboard management and inspection tools such as xclip and you can bind keys to do arbitrary commands with a bunch of tools.
There's a wide variety of ways to send stuff over the network as well.
The architecture is pretty obvious
Copy on remote, clipboard manager emits over network, local server picks up text, puts in clipboard.
This is like a few hours at most
This appears to be for the terminal emulator. I gave up on X11 and its successors many years ago in favor of what was called, at the time, "VGA textmode". No framebuffer, unfortunately. Have not used a mouse outside of work in thirty years. "Clips" for me are captured (copied) from pipes or from pseudo-terminals, saved in buffers and pasted into pipes and pseudo-terminals.
A "terminal multiplexer", i.e., tmux, is the solution I use as a "clipboard", namely what tmux calls "saved buffers". Specifically the commands I use are load-buffer, save-buffer, paste-buffer, list-buffers and delete-buffer.
So what the heck is "the terminal". The way HN commenters use the term it probably means "the terminal emulator". But perhaps it is an umbrella term for textmode, multiplexer and emulator.
It's pretty clear what "terminal" means in this context. Nobody uses the term in the classical mainframe sense, so "emulator" is implied.
And you brought up "multiplexer". It's neat that you use it for clipboard management, but this tool does much more than that.
Very few people use hardware terminals; the scarcity has driven prices up to the point where it is sometimes cheaper to get a full computer, monitor, keyboard and serial adapter than to buy a working VT-series terminal.
> cb > really_large_objects.txt
Did not expect that.
It’s so frequently used it deserves prime physical real estate of one or two dedicated keys. It deserves a standardized API for at least image data, text, files, and an extension system, that works the same across platforms. Most importantly it needs discoverable, inspectable consistent UX that can be taught in schools and to seniors.
I’m not saying it’s easy, clipboard is almost by definition shared mutable state, which is hard and messy. Then it needs to work with touch screens, cli and maybe even other interfaces. And its closely related cousins, like drag and drop and selections, are also important and related UX considerations.
Disclaimer: I’m a little bit intentionally provocative, and I should probably really be more careful what I wish for, since any major change inevitably runs into (major) problems (see exhibit A – ipv6). I am partly just venting - after all these decades we certainly have enough experience to build something better. We certainly deserve it.