upload (1215B)
1 #!/bin/sh 2 # Upload files using `transfer.sh`. 3 if [ "$#" -eq 0 ]; then 4 filename="$(basename "$0")" 5 printf "No arguments specified.\nUsage:\n %s <file|directory>\n ... | %s <file_name>\n" "$filename" "$filename" 6 exit 2 7 fi 8 9 if tty -s; then 10 file="$1" 11 file_name=$(basename "$file") 12 if [ ! -e "$file" ]; then 13 echo "$file: No such file or directory">&2 14 exit 2 15 fi 16 if [ -d "$file" ]; then 17 file_name="$file.zip" 18 tree -C --noreport "$file" 19 printf "\nAre you sure you want to upload the %s (as %s) directory? [y/N] " "$file" "$file_name" 20 read -r ASK; case "$ASK" in 21 [Yy][Ee][Ss]|[Yy]) (cd "$file"&&zip -r -q - .) | curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name" | tee /dev/null ;; 22 *) exit 2 ;; 23 esac 24 else 25 printf "Are you sure you want to upload %s? [y/N] " "$file_name" 26 read -r ASK; case "$ASK" in 27 [Yy][Ee][Ss]|[Yy]) curl --progress-bar --upload-file "$file" "https://transfer.sh/$file_name" | tee /dev/null ;; 28 *) exit 2 ;; 29 esac 30 fi 31 else 32 file_name="$1" 33 curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name" | tee /dev/null 34 fi