Debian Codegraph @

plugins/upload

raw
1 #!/usr/bin/env sh
2
3 # Description: Selections are archived into a tar file (uncompressed) and uploaded to file.io
4 # For single files:
5 # Paste contents of a text file to http://ix.io
6 # Upload a binary file to file.io
7 #
8 # Dependencies: curl, jq, tar, file with `--mime-type` support
9 #
10 # Note: Binary file set to expire after a week
11 #
12 # Shell: POSIX compliant
13 # Author: Arun Prakash Jana
14
15 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
16 if [ -s "$selection" ]; then
17 xargs -0 tar -c < "$selection" | \
18 curl -s -F "file=@/dev/stdin;filename=selection.tar" 'https://file.io/?expires=1w' | \
19 jq '.link' | tr -d '"'
20
21 # Clear selection
22 printf "-" > "$NNN_PIPE"
23 else
24 if [ -n "$1" ] && [ -s "$1" ]; then
25 if file --mime-type "$1" | grep -q -F "text/"; then
26 curl -F "file=@$1" https://0x0.st
27 else
28 # Upload the file, show the download link and wait till user presses any key
29 curl -s -F "file=@$1" https://file.io/?expires=1w | jq '.link' | tr -d '"'
30 # To write download link to "$1".loc and exit
31 # curl -s -F "file=@$1" https://file.io/?expires=1w -o `basename "$1"`.loc
32 fi
33 else
34 printf "empty file!"
35 fi
36 fi
37
38 read -r _