Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chaifeng
Last active March 11, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaifeng/fecf0ffd3282bb669633222737c4b390 to your computer and use it in GitHub Desktop.
Save chaifeng/fecf0ffd3282bb669633222737c4b390 to your computer and use it in GitHub Desktop.
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