Skip to content

Instantly share code, notes, and snippets.

@bsidhom
Created October 10, 2019 21:54
Show Gist options
  • Save bsidhom/b7541bdeb198d0e7951e5096afab99e2 to your computer and use it in GitHub Desktop.
Save bsidhom/b7541bdeb198d0e7951e5096afab99e2 to your computer and use it in GitHub Desktop.
Copy file (with mime-type) to clipboard. Useful for copying images to clipboard from the command line.
#!/usr/bin/env bash
set -euo pipefail
function main() {
if [[ "$#" != 1 ]] ; then
printf "usage: %s <input file>\n" "$0" >&2
return 2
fi
local file="$1"
xclip \
-in \
-selection clipboard \
-target "$(file --brief --mime-type "$file")" \
<"$file"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment