Created
October 10, 2019 21:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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