3 # Description: Selections are uploaded using Firefox Send
5 # Upload to Firefox Send if ffsend is found, else
6 # Paste contents of a text a file http://ix.io
7 # Upload a binary file to file.io
9 # Dependencies: ffsend (https://github.com/timvisee/ffsend), curl, jq, tr
11 # Note: Binary file set to expire after a week
13 # Shell: POSIX compliant
14 # Author: Arun Prakash Jana
16 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
17 if [ -s "$selection" ]; then
18 if type ffsend >/dev/null 2>&1; then
19 # File name will be randomized foo.tar
20 xargs -0 < "$selection" ffsend u
22 printf "ffsend is required to upload selection."
26 printf "-" > "$NNN_PIPE"
28 if [ -n "$1" ] && [ -s "$1" ]; then
29 if type ffsend >/dev/null 2>&1; then
31 elif [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "text" ]; then
32 curl -F "f:1=@$1" ix.io
34 # Upload the file, show the download link and wait till user presses any key
35 curl -s -F "file=@$1" https://file.io/?expires=1w | jq '.link' | tr -d '"'
37 # To write download link to "$1".loc and exit
38 # curl -s -F "file=@$1" https://file.io/?expires=1w -o `basename "$1"`.loc