up.sh in git
UP(1)                   FreeBSD General Commands Manual                  UP(1)

NAME
     up – upload file

SYNOPSIS
     up [-hs] [file]

DESCRIPTION
     up uploads a file to temp.causal.agency with scp(1).  If no file is
     provided, standard input is read and uploaded as text.

     The destination file name is chosen using date(1) and openssl(1) rand.
     The URL of the uploaded file is printed and copied to the pasteboard with
     pbcopy(1) if available.

     The arguments are as follows:

     -h      Use hi(1) to produce an HTML file for upload.

     -s      Use screencapture(1) to produce a PNG file for upload.  The file
             is optimized by pngo(1) if available.

     Any arguments after ‘--’ are passed to hi(1) and screencapture(1),
     respectively.

FreeBSD 12.0-RELEASE-p4        February 2, 2019        FreeBSD 12.0-RELEASE-p4
#!/bin/sh
set -eu

readonly Host='temp.causal.agency'

upload() {
	local src ext ts rand url
	src=$1
	ext=${src##*.}
	ts=$(date +'%s')
	rand=$(openssl rand -hex 4)
	url=$(printf '%s/%x%s.%s' "$Host" "$ts" "$rand" "$ext")
	scp -q "$src" "${Host}:/usr/local/www/${url}"
	echo "https://${url}"
}

temp() {
	temp=$(mktemp -d)
	trap "rm -r '$temp'" EXIT
}

uploadText() {
	temp
	cat > "${temp}/input.txt"
	upload "${temp}/input.txt"
}

uploadHi() {
	temp
	hi -f html -o document,anchor,tab=4 "$@" > "${temp}/hi.html"
	upload "${temp}/hi.html"
}

uploadScreen() {
	temp
	screencapture -i "$@" "${temp}/capture.png"
	pngo "${temp}/capture.png" || true
	upload "${temp}/capture.png"
}

args=$(setopt 'hs' "$@")
eval set -- "$args"
for opt; do
	case "$opt" in
		(-h) shift; fn=uploadHi;;
		(-s) shift; fn=uploadScreen;;
		(--) shift; break;;
	esac
done
[ $# -eq 0 ] && : ${fn:=uploadText}
: ${fn:=upload}

url=$($fn "$@")
printf '%s' "$url" | pbcopy || true
echo "$url"