# Shell helpers for estampa. Source this from your shell rc: # # export ESTAMPA_HOST=estampa@paste.example.com # . /path/to/extras/estampa.sh # # Optional: # export ESTAMPA_URL=https://paste.example.com # Defaults to "https://" + the host part of $ESTAMPA_HOST. # # Functions: # estampaup ./file.txt upload a file, print the URL. # estampaste file.txt upload the clipboard as , print the URL. # # estampaste uses wl-paste on Wayland and pbpaste on macOS. estampaup() { if [ $# -ne 1 ]; then printf 'usage: estampaup \n' >&2 return 2 fi if [ ! -f "$1" ]; then printf 'estampaup: not a file: %s\n' "$1" >&2 return 1 fi local host="${ESTAMPA_HOST:?set ESTAMPA_HOST=estampa@paste.example.com}" local url="${ESTAMPA_URL:-https://${host#*@}}" local name name=$(basename -- "$1") scp -q "$1" "$host:./$name" || return $? printf '%s/%s\n' "$url" "$name" } estampaste() { if [ $# -ne 1 ]; then printf 'usage: estampaste \n' >&2 return 2 fi local host="${ESTAMPA_HOST:?set ESTAMPA_HOST=estampa@paste.example.com}" local url="${ESTAMPA_URL:-https://${host#*@}}" local name="$1" local clip if command -v wl-paste >/dev/null 2>&1; then clip=wl-paste elif command -v pbpaste >/dev/null 2>&1; then clip=pbpaste else printf 'estampaste: no clipboard tool (need wl-paste or pbpaste)\n' >&2 return 1 fi local tmp tmp=$(mktemp) || return 1 # >| overrides zsh/bash `noclobber`; mktemp just created the file # and we intentionally want to write over it. if ! $clip >|"$tmp"; then rm -f "$tmp" return 1 fi if [ ! -s "$tmp" ]; then printf 'estampaste: clipboard is empty\n' >&2 rm -f "$tmp" return 1 fi # mktemp creates 600; scp preserves source mode, so without this # the upload lands unreadable to the nginx user. chmod 644 "$tmp" if ! scp -q "$tmp" "$host:./$name"; then rm -f "$tmp" return 1 fi rm -f "$tmp" printf '%s/%s\n' "$url" "$name" }