35 lines
1 KiB
Bash
Executable file
35 lines
1 KiB
Bash
Executable file
#!/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
|
|
if wl-paste --list-types | grep -qv '^text/plain$'; then
|
|
# clipboard contains a file
|
|
tempdir=$(mktemp -d)
|
|
wl-paste >temp
|
|
extension=$(grep -E "^$(wl-paste --list-types)" /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
|
|
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
|