Skip to content

Instantly share code, notes, and snippets.

Last active Apr 4, 2020
What would you like to do?
if [[ "$1" == "-h" || "$1" == "-?" || "$1" == "--help" ]]; then
echo 'copycat: copy stdin or files specified on command line to Wayland and/or X clipboard'
echo 'performs automatic mimetype detection like wl-copy via file under X'
echo 'usage:'
echo ' copycat: copy stdin to clipboard'
echo ' copycat <-h|--help|-?>: display usage help'
echo ' copycat <files...>: concatenate each file, then copy to clipboard'
echo 'if $WAYLAND_DISPLAY is set, delegates to wl-copy'
echo 'otherwise, uses xclip and file'
echo 'similarly to cat, - may be specified as a filename to allow concatening stdin with files'
) 1>&2
exit 0
if [ -n "$WAYLAND_DISPLAY" ]; then
cat -- "$@" | wl-copy
echo "copycat: copied to Wayland clipboard" 1>&2
cat -- "$@" > "$tmpfile"
mime=$(file -b --mime-type "$tmpfile")
xclip -t "$mime" -selection clipboard "$tmpfile"
rm "$tmpfile"
echo "copycat: copied to X clipboard, detected mimetype $mime" 1>&2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment