From 293620d74ca52917a59a681dd6bb3b436123617c Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 18 Dec 2017 01:12:50 -0500 Subject: [PATCH] Rewrite bin/transfer --- bin/transfer | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/transfer b/bin/transfer index d9e82a16..162a53e4 100755 --- a/bin/transfer +++ b/bin/transfer @@ -1,16 +1,22 @@ #!/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 url="https://transfer.sh" 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') curl --progress-bar --upload-file "$1" "$url/$basefile" >>"$tmpfile" else curl --progress-bar --upload-file "-" "$url/$1" >>"$tmpfile" fi +cat "$tmpfile" | clip cat "$tmpfile" -rm -f "$tmpfile" - -# vim:set ft=sh: