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

NAME
     up – upload file

SYNOPSIS
     up [-h] [file]
     up -c | -t command ...
     up -s

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:

     -c      Run a command to produce a text file for upload.

     -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.

     -t      Run a command with ptee(1) and shotty(1) to produce an HTML file
             for upload.

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

FreeBSD 12.0-RELEASE-p10         July 15, 2019        FreeBSD 12.0-RELEASE-p10
#!/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"
}

uploadCommand() {
	temp
	echo "$ $*" > "${temp}/exec.txt"
	"$@" >> "${temp}/exec.txt"
	upload "${temp}/exec.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"
}

uploadTerminal() {
	temp
	cat > "${temp}/term.html" <<-EOF
	<!DOCTYPE html>
	<title>${1}</title>
	<style>
	$(scheme -s)
	</style>
	EOF
	ptee "$@" | shotty -Bcs >> "${temp}/term.html"
	upload "${temp}/term.html"
}

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

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