2016-11-10 10:42:20 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-12-17 22:12:50 -08:00
|
|
|
if (( $# == 0 )); then
|
|
|
|
>&2 echo "Forgot to specify a destination filename. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-12-05 22:39:10 -08:00
|
|
|
# Upload file/stdin to transfer.sh
|
2016-11-10 10:42:20 -08:00
|
|
|
url="https://transfer.sh"
|
|
|
|
tmpfile=$(mktemp -t transferXXX)
|
2017-12-17 22:12:50 -08:00
|
|
|
cleanup() { rm -f "$tmpfile"; }
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
|
|
|
if tty -s; then
|
2017-12-05 22:39:10 -08:00
|
|
|
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
|
|
|
|
curl --progress-bar --upload-file "$1" "$url/$basefile" >>"$tmpfile"
|
2016-11-10 10:42:20 -08:00
|
|
|
else
|
2017-12-05 22:39:10 -08:00
|
|
|
curl --progress-bar --upload-file "-" "$url/$1" >>"$tmpfile"
|
2016-11-10 10:42:20 -08:00
|
|
|
fi
|
|
|
|
|
2017-12-17 22:12:50 -08:00
|
|
|
cat "$tmpfile" | clip
|
2017-12-05 22:39:10 -08:00
|
|
|
cat "$tmpfile"
|