Have you ever typed ctrl-c instead of ctrl-v and had to recopy again?
Have you ever needed to copy and paste multiple entries at once from a page causing you to switch back and forth?
Have you ever needed to copy the output of a program running in the terminal?
I did, and got fed up with them almost 5 years ago, I'll show you how you can eliminate these problems.
Most of my clipboard-related frustration came from the fact, that default clipboards in the operating systems store only one entry at a time. If I were to access the clipboard history, most of my problems were gone.
Luckily there are apps for that.
The latest version of Windows 10 have a setting to make clipboard history available in the
System settings under
Clipboard history. It makes clipboard history available with
win+V key. Not too configurable, but perfectly usable.
On Mac you can use a secondary clipboard with
ctrl+k (copy) and
ctrl+y (paste), alongside
cmd+c (copy) and
cmd+v (paste). You can still only have 2 separate entries at once.
I started to use Ditto to eliminate this problem.
I loved that I could access my previous clips throughout the day.
It had configurable shortcuts to access the last 10 entries separately.
The only problem I had with it, that it only worked for windows.
I love that it has a configurable clipboard size, I can search through the entries, and it has a configurable shortcut to
Show main window under mouse cursor that can speed up work.
In case I copy sensitive data, I can turn off clipboard monitoring all at once with a configurable shortcut:
Toggle Clipboard Storing.
My only problem with it is that it sometimes tends to quit unexpectedly on mac. According to their github issues they're working on it.
In the command line you can take advantage of the operating system's pipeline. Imagine copy as a utility that consumes text, and paste as one that produce text, and when you use them the clipboard changes accordingly.
Let's see what are the exact utilities that can be used for different systems.
Mac has built-in utility commands to
pbpaste to the clipboard.
# copy text to clipboard by piping to `pbcopy` echo "Text to copy" | pbcopy # paste text from clipboard by piping from `pbpaste` pbpaste | less
# Install it with the available package manager. # Add to e.g: ~/.bash_profile to load on startup alias pbcopy='xclip -selection clipboard' alias pbpaste='xclip -selection clipboard -o'
On linux servers that does not have window manager I did not yet see the point to investigate this further.
Windows has builtin clip.exe.
Unfortunately, it can only copy TO the clipboard, can not read from it.
If you need access to the clipboard you need to use Get-Clipboard powershell module.
REM copy to clipboard with clip.exe echo "Text to copy" | clip REM get data from clipboard powershell -command "Get-Clipboard" REM get data from clipboard into file powershell -command "Get-Clipboard" > file.txt
If for some reason you still use Cygwin,
you're in luck!
It makes Windows clipboard available as
# copy text to clipboard by redirecting to `/dev/clipboard` echo "Text to copy" > /dev/clipboard # paste text from clipboard by reading from `/dev/clipboard` cat /dev/clipboard
In web browsers you can use the modern Clipboard API to interact with the clipboard. Previously you could use
document.execCommand() but it's obsolete, that means it might still work, but it's discouraged.
For browser support see clipboard at caniuse.com.
For up to date and extensive examples see these pages sbove.
In Chrome developer Console you can use copy(object) builtin function to put an object to the clipboard.
It can be handy during debugging. Combined with $0 you can copy whole dom elements quickly.
copy($0) copy($0.value) copy(window.myGlobalObject)