os/x11/ X11ClipboardUtils
X11 Clipboard Utilities
I use xsel
.
OS Agnostic
I use the following scripts with Linux, macos and Cygwin under Windows
#!/bin/dash
# copy to clipboard
if [ -n "$DISPLAY" ]; then # X11
cat "$@" | xsel -i -b
elif [ -d "/Applications" ]; then # macos
cat "$@" | pbcopy
elif [ -d "/cygdrive/c/cygwin64" ]; then # cygwin
cat "$@" > /dev/clipboard
else
echo "Cannot copy as not gui" > /dev/stderr
fi
to copy, and
#!/bin/dash
if [ -n "$DISPLAY" ]; then # X11
paste() { xsel -o -b; }
elif [ -d "/Applications" ]; then # macos
paste() { pbpaste; }
elif [ -d "/cygdrive/c/cygwin64" ]; then # cygwin
paste() { cat /dev/clipboard; }
else
echo "Cannot paste as not gui" > /dev/stderr
fi
if [ -n "$1" ]; then
paste | tee "$1"
else
paste
fi
to paste.