Updates transfer.sh plugin: no longer uses a temp file ; fixes issue with filenames with special characters ; starts using omz_urlencode() ;

This commit is contained in:
Gabriel Kaam 2015-09-29 20:59:33 +02:00
commit 7828042726

View file

@ -1,20 +1,25 @@
# From https://transfer.sh/
# Modified by Gabriel Kaam <gabriel@kaam.fr>
function transfer() { function transfer() {
if [ $# -eq 0 ]; then if [[ $# -eq 0 ]]; then
echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" cat<<EOF
No arguments specified. Usage:
transfer /tmp/test.md
cat /tmp/test.md | transfer test.md
EOF
return 1 return 1
fi fi
tmpfile=$( mktemp -t transferXXX ) basefile=$(omz_urlencode "${1:t}")
if tty -s; then if tty -s; then
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g') url=$(curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile")
curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile
else else
curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile url=$(curl --progress-bar --upload-file "-" "https://transfer.sh/$basefile")
fi fi
cat $tmpfile echo $url
rm -f $tmpfile
} }
alias transfer=transfer alias transfer=transfer