Skip to content

Instantly share code, notes, and snippets.

@niedzielski
Last active December 26, 2017 20:06
Show Gist options
  • Select an option

  • Save niedzielski/b5379452552c7ecbffed3cc7f0bbb089 to your computer and use it in GitHub Desktop.

Select an option

Save niedzielski/b5379452552c7ecbffed3cc7f0bbb089 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment