#!/bin/env bash # if the clipboard is plain/text, we assume it's a path # otherwise, we assume it's a mime-type to be pasted TYPE=$(wl-paste --list-types) if "$TYPE" | grep -qv '^text/plain$'; then # clipboard contains a file tempdir=$(mktemp -d) wl-paste >temp extension=$(grep -E "^$TYPE" /etc/mime.types | awk '{print $2}') # echo -n "File name: " >&2 # read -r user_input read -r -p "$(echo -n "Enter file name (extension .$extension will be appended): " >&2)" user_input attachment="$tempdir/$user_input.$extension" read -r -p "$(echo -n "Your file will be written to $attachment and attached. Confirm (y/n): " >&2)" confirm case "$confirm" in y) wl-paste >"$attachment" echo "$attachment" ;; *) exit 1 ;; esac elif "$TYPE" | grep -q '^text/uri-list$' && "$TYPE" | grep -q '^file://'; then # convert URI into standard path echo "hola" else # clipboard contains a string (treat as path) read -r -p "$(echo -n "Your clipboard contains $(wl-paste), which will be attached as a file path. Confirm (y/n): " >&2)" confirm case "$confirm" in y) wl-paste ;; *) exit 1 ;; esac fi