Is it possible to pipe to/from the clipboard in Bash?
Whether it is piping to/from a device handle or using an auxiliary application, I can't find anything.
For example, if /dev/clip
was a device linking to the clipboard we could do:
cat /dev/clip # Dump the contents of the clipboard
cat foo > /dev/clip # Dump the contents of "foo" into the clipboard
Although >1 year later, I share a slightly different solution. Hope this is useful for somebody.
Yesterday I found myself with the question: "How to share the clipboard between different user sessions?". When switching between sessions with ctrlaltF7 - ctrlaltF8, in fact, you can't paste what you copied.
I came up with the following quick & dirty solution, based on a named pipe. It is surely quite bare and raw, but I found it functional:
then in the sending terminal
last, in the receiving terminal:
Now, you type or paste anything in the first terminal, and (after hitting return), it will appear immediately in the receiving terminal, from where you can Copy/Paste again anywhere you like.
Of course this doesn't just strictly take the content from user1's clipboard to make it available in user2's clipboard, but rather it requires an additional pair of Paste & Copy clicks.
A few Windows programs I wrote years ago. They allow you dump, push, append and print the clipboard. It works like this:
It includes source code: cmd_clip.zip
On macOS use the built in
pbcopy
andpbpaste
commands.For example, if you run
the contents of the
~/.bashrc
file will be available for pasting with theCmd
+v
shortcut.xsel on Debian/Ubuntu/Mint
Install
There are different clipboards in Linux; the X server has one, the window manager might have another one, etc. There is no standard device.
Oh, yes, on CLI, the screen program has its own clipboard as well, as do some other applications like Emacs and vi.
In X, you can use xclip.
You can check this thread for other possible answers: http://unix.derkeiler.com/Newsgroups/comp.unix.shell/2004-07/0919.html
Install
If you do not have access to
apt-get
norpacman
, nordnf
, the sources are available on sourceforge.Set-up
Bash
In
~/.bash_aliases
, add:Do not forget to load your new configuration using
. ~/.bash_aliases
or by restarting your profile.Fish
In
~/.config/fish/config.fish
, add:Do not forget to restart your fish instance by restarting your terminal for changes to apply.
Usage
You can now use
setclip
andgetclip
, e.g: