From feb2f7c7c71e7c93807e9f16b9d883144230a0a9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 10 Nov 2016 19:42:20 +0100 Subject: [PATCH] +bin/{bin,transfer} scripts for sprunge.us and transfer.sh --- bin/bin | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/transfer | 16 +++++++++++++ 2 files changed, 83 insertions(+) create mode 100755 bin/bin create mode 100644 bin/transfer diff --git a/bin/bin b/bin/bin new file mode 100755 index 00000000..48d61cda --- /dev/null +++ b/bin/bin @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +# Sends file(s) or stdin to http://sprunge.us + +set -e + +usage() { + more <&2 echo "$OPTARG requires an argument" + usage + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + +if (($# == 0)) && [[ -t 0 ]]; then + >&2 echo "Nothing in stdin and no files specified!" + >&2 usage + exit 1 +fi + +# Naive lang detection from file extension +[[ "$1" = *.* && -z "$lang" ]] && lang="?${1##*.}" + +# Read from stdin or read file(s) +url=$(sprunge $1) + +# Assemble URL+langstr and send to clipboard +printf "%s%s" "$url" "$lang" | pbcopy + +# Show URL to interactive users +[[ -t 0 ]] && pbpaste diff --git a/bin/transfer b/bin/transfer new file mode 100644 index 00000000..a7aa21fb --- /dev/null +++ b/bin/transfer @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Upload file to transfer.sh +url="https://transfer.sh" +tmpfile=$(mktemp -t transferXXX) +if [[ -t 0 ]]; 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 +rm -f $tmpfile + +# vim:set ft=sh: