sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

upload (1390B)


      1 #!/usr/bin/env sh
      2 
      3 # Description: Selections are uploaded using Firefox Send
      4 #              For single files:
      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
      8 #
      9 # Dependencies: ffsend (https://github.com/timvisee/ffsend), curl, jq, tr
     10 #
     11 # Note: Binary file set to expire after a week
     12 #
     13 # Shell: POSIX compliant
     14 # Author: Arun Prakash Jana
     15 
     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
     21     else
     22       printf "ffsend is required to upload selection."
     23     fi
     24 
     25     # Clear selection
     26     printf "-" > "$NNN_PIPE"
     27 else
     28     if [ -n "$1" ] && [ -s "$1" ]; then
     29 	if type ffsend >/dev/null 2>&1; then
     30 	    ffsend -fiq u "$1"
     31 	elif [ "$(mimetype --output-format %m "$1" | awk -F '/' '{print $1}')" = "text" ]; then
     32 	    curl -F "f:1=@$1" ix.io
     33 	else
     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 '"'
     36 
     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
     39 	fi
     40     else
     41 	printf "empty file!"
     42     fi
     43 fi
     44 
     45 read -r _