aboutsummaryrefslogtreecommitdiff
path: root/extras
diff options
context:
space:
mode:
authorRuben Beltran del Rio <jj@r.bdr.sh>2026-04-30 16:10:11 +0200
committerRuben Beltran del Rio <jj@r.bdr.sh>2026-04-30 16:10:20 +0200
commit42fc9a475070728fde00909310cd7a995168425b (patch)
tree9f43a6683750414dfe1ecd0b2ae7de42468550de /extras
parent8cc11c52a88ec78d175b3ec8de854916f631caab (diff)
Add some shell helpers
Diffstat (limited to 'extras')
-rwxr-xr-xextras/estampa-ssh2
-rw-r--r--extras/estampa.sh75
2 files changed, 76 insertions, 1 deletions
diff --git a/extras/estampa-ssh b/extras/estampa-ssh
index f1cbd08..4b2202f 100755
--- a/extras/estampa-ssh
+++ b/extras/estampa-ssh
@@ -2,7 +2,7 @@
# estampa-ssh: forced command for the upload account in ~/.ssh/authorized_keys.
#
# Usage in authorized_keys:
-# command="/usr/local/bin/estampa-ssh /srv/estampa/pastes",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding ssh-ed25519 AAAA... uploader
+# command="/usr/local/bin/estampa-ssh /srv/estampa",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding ssh-ed25519 AAAA... uploader
#
# On every incoming SSH session this:
# 1. prunes pastes older than one week from $1 (best-effort, never blocks),
diff --git a/extras/estampa.sh b/extras/estampa.sh
new file mode 100644
index 0000000..53a705a
--- /dev/null
+++ b/extras/estampa.sh
@@ -0,0 +1,75 @@
+# 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 <file.txt>, print the URL.
+#
+# estampaste uses wl-paste on Wayland and pbpaste on macOS.
+
+estampaup() {
+ if [ $# -ne 1 ]; then
+ printf 'usage: estampaup <file>\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 <filename>\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
+
+ if ! scp -q "$tmp" "$host:./$name"; then
+ rm -f "$tmp"
+ return 1
+ fi
+ rm -f "$tmp"
+ printf '%s/%s\n' "$url" "$name"
+}