Rewrite bin/transfer
This commit is contained in:
parent
e8989afb7a
commit
293620d74c
14
bin/transfer
14
bin/transfer
|
@ -1,16 +1,22 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if (( $# == 0 )); then
|
||||||
|
>&2 echo "Forgot to specify a destination filename. Aborting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Upload file/stdin to transfer.sh
|
# Upload file/stdin to transfer.sh
|
||||||
url="https://transfer.sh"
|
url="https://transfer.sh"
|
||||||
tmpfile=$(mktemp -t transferXXX)
|
tmpfile=$(mktemp -t transferXXX)
|
||||||
if [[ -t 0 ]]; then
|
cleanup() { rm -f "$tmpfile"; }
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
if tty -s; then
|
||||||
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
|
basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
|
||||||
curl --progress-bar --upload-file "$1" "$url/$basefile" >>"$tmpfile"
|
curl --progress-bar --upload-file "$1" "$url/$basefile" >>"$tmpfile"
|
||||||
else
|
else
|
||||||
curl --progress-bar --upload-file "-" "$url/$1" >>"$tmpfile"
|
curl --progress-bar --upload-file "-" "$url/$1" >>"$tmpfile"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
cat "$tmpfile" | clip
|
||||||
cat "$tmpfile"
|
cat "$tmpfile"
|
||||||
rm -f "$tmpfile"
|
|
||||||
|
|
||||||
# vim:set ft=sh:
|
|
||||||
|
|
Loading…
Reference in a new issue