Last active
March 11, 2017 14:50
-
-
Save chaifeng/fecf0ffd3282bb669633222737c4b390 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
transfer() { | |
if [ $# -eq 0 ]; then | |
echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; | |
return 1; | |
fi | |
tmpfile="$( mktemp -t transferXXX )"; | |
query="$1"; | |
[[ -z "$query" ]] && exit 1; | |
if ! tty -s; then | |
pv -ra | curl --silent --upload-file "-" "https://d.chaifeng.com/$query" >> "$tmpfile" ; | |
elif [[ $# > 1 ]] || [[ -d "$query" ]]; then | |
[[ $# > 1 ]] && query="archive-$(date +%Y%m%d%H%M%S)"; | |
zip -q -r - "$@" | pv -ra | curl --silent --upload-file "-" "https://d.chaifeng.com/${query}.zip" >> $tmpfile ; | |
elif [[ -f "$query" ]]; then | |
curl --progress-bar --upload-file "$query" "https://d.chaifeng.com/" >> "$tmpfile"; | |
else | |
echo "Error: '$query' not found."; | |
exit 2; | |
fi | |
cat $tmpfile; | |
rm -f $tmpfile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment