Seamlessly Work Across GUIs and Command Line with Copy and Paste
The clipboard provides a very convenient way to exchange data between different programs and is especially convenient for working with GUIs which can't use pipelines. Add the following function to your .zshrc / .bashrc:
cb()
{
# OS X: pbcopy / pbpaste
# Cygwin: putclip / getclip
# Linux: xclip (and others)
if [[ ! -t 0 ]]
then
# Input (copy).
xclip -sel c
else
# Output (paste).
xclip -sel c -o
fi
}
Examples:
# Check for the existence of a collection of files.
ls $(cb)
# Copy the webpage at the clipboard URL.
curl $(cb)|cb
# Copy the concatenate of a collection of files.
cb|xargs -rd\\n cat|cb
Written by Stephen Niedzielski
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#