summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--bin/.gitignore1
-rw-r--r--bin/Makefile8
-rw-r--r--bin/README3
-rw-r--r--bin/bin.75
-rw-r--r--bin/man1/up.160
-rw-r--r--bin/up.sh58
-rwxr-xr-xhome/.local/bin/hup7
-rwxr-xr-xhome/.local/bin/sup8
-rwxr-xr-xhome/.local/bin/tup7
-rwxr-xr-xhome/.local/bin/up12
10 files changed, 133 insertions, 36 deletions
diff --git a/bin/.gitignore b/bin/.gitignore
index 2cc2d5ec..7a4e360f 100644
--- a/bin/.gitignore
+++ b/bin/.gitignore
@@ -25,6 +25,7 @@ scheme.h
 scheme.png
 tags
 ttpre
+up
 wake
 wat
 xx
diff --git a/bin/Makefile b/bin/Makefile
index ff41e6a1..9fa34ce9 100644
--- a/bin/Makefile
+++ b/bin/Makefile
@@ -19,6 +19,7 @@ BINS += pngo
 BINS += psf2png
 BINS += scheme
 BINS += ttpre
+BINS += up
 BINS += wake
 BINS += xx
 
@@ -106,6 +107,13 @@ $(HTMLS): ttpre hi
 	man -P cat ./man1/$(<:%.c=%.1) | ./ttpre >> $@
 	./hi -f html -o inline,tab=4 $< >> $@
 
+.sh.html:
+	@echo '<!DOCTYPE html>' > $@
+	@echo '<title>$(<:%.sh=%)</title>' >> $@
+	@echo '<code><a href="$(GITEA_URL)/$<">$< in git</a></code>' >> $@
+	man -P cat ./man1/$(<:%.sh=%.1) | ./ttpre >> $@
+	./hi -f html -o inline,tab=4 $< >> $@
+
 clean:
 	rm -f $(BINS_ALL) $(LINKS) tags scheme.h scheme.png *.o *.html
 
diff --git a/bin/README b/bin/README
index 53992a5d..74de8a52 100644
--- a/bin/README
+++ b/bin/README
@@ -24,6 +24,7 @@ DESCRIPTION
      psf2png(1)  PSF2 to PNG renderer
      psfed(1)    PSF2 font editor
      ttpre(1)    man output to HTML
+     up(1)       upload file
      wake(1)     wake-on-LAN
      wat(1)      watch files
      xx(1)       hexdump
@@ -34,4 +35,4 @@ DESCRIPTION
            GFX=fb
            GFX=x11
 
-Causal Agency                  Feburary 6, 2019                  Causal Agency
+Causal Agency                  Feburary 12, 2019                 Causal Agency
diff --git a/bin/bin.7 b/bin/bin.7
index 201ac3b0..8d5239c1 100644
--- a/bin/bin.7
+++ b/bin/bin.7
@@ -1,4 +1,4 @@
-.Dd Feburary 6, 2019
+.Dd Feburary 12, 2019
 .Dt BIN 7
 .Os "Causal Agency"
 .
@@ -67,6 +67,9 @@ PSF2 font editor
 .It Xr ttpre 1
 man output to HTML
 .
+.It Xr up 1
+upload file
+.
 .It Xr wake 1
 wake-on-LAN
 .
diff --git a/bin/man1/up.1 b/bin/man1/up.1
new file mode 100644
index 00000000..f479b7ad
--- /dev/null
+++ b/bin/man1/up.1
@@ -0,0 +1,60 @@
+.Dd February 2, 2019
+.Dt UP 1
+.Os
+.
+.Sh NAME
+.Nm up
+.Nd upload file
+.
+.Sh SYNOPSIS
+.Nm
+.Op Fl hs
+.Op Ar file
+.
+.Sh DESCRIPTION
+.Nm
+uploads a file
+to temp.causal.agency with
+.Xr scp 1 .
+If no
+.Ar file
+is provided,
+standard input is read
+and uploaded as text.
+.
+.Pp
+The destination file name
+is chosen using
+.Xr date 1
+and
+.Xr openssl 1
+.Cm rand .
+The URL of the uploaded file is printed
+and copied to the pasteboard with
+.Xr pbcopy 1
+if available.
+.
+.Pp
+The arguments are as follows:
+.Bl -tag -width Ds
+.It Fl h
+Use
+.Xr hi 1
+to produce an HTML file for upload.
+.It Fl s
+Use
+.Xr screencapture 1
+to produce a PNG file for upload.
+The file is optimized by
+.Xr pngo 1
+if available.
+.El
+.
+.Pp
+Any arguments after
+.Ql \-\-
+are passed to
+.Xr hi 1
+and
+.Xr screencapture 1 ,
+respectively.
diff --git a/bin/up.sh b/bin/up.sh
new file mode 100644
index 00000000..1ca34a1c
--- /dev/null
+++ b/bin/up.sh
@@ -0,0 +1,58 @@
+#!/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 rmtemp EXIT
+}
+rmtemp() {
+	rm -r "$temp"
+}
+
+uploadText() {
+	temp
+	cat > "${temp}/input.txt"
+	upload "${temp}/input.txt"
+}
+
+uploadHi() {
+	temp
+	hi -f html -o document,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=$(getopt 'hs' $*)
+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 "$@")
+echo "$url" | pbcopy || true
+echo "$url"
diff --git a/home/.local/bin/hup b/home/.local/bin/hup
deleted file mode 100755
index 4fc5d7ae..00000000
--- a/home/.local/bin/hup
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-set -eu
-
-dir=$(mktemp -d)
-hi -f html -o document,tab=4 "$@" > "$dir/hi.html"
-up "$dir/hi.html"
-rm -r "$dir"
diff --git a/home/.local/bin/sup b/home/.local/bin/sup
deleted file mode 100755
index 33b268c8..00000000
--- a/home/.local/bin/sup
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-set -e -u
-
-dir=$(mktemp -d)
-screencapture -i "$dir/capture.png"
-type pngo > /dev/null && pngo "$dir/capture.png"
-up "$dir/capture.png"
-rm -r "$dir"
diff --git a/home/.local/bin/tup b/home/.local/bin/tup
deleted file mode 100755
index 543038da..00000000
--- a/home/.local/bin/tup
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/bin/sh
-set -e -u
-
-dir=$(mktemp -d)
-cat > "$dir/input.txt"
-up "$dir/input.txt"
-rm -r "$dir"
diff --git a/home/.local/bin/up b/home/.local/bin/up
deleted file mode 100755
index 4f832a3c..00000000
--- a/home/.local/bin/up
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-set -e -u
-
-ts=$(date +%s)
-rand=$(openssl rand -hex 4)
-ext=${1##*.}
-url=$(printf 'temp.causal.agency/%x%s.%s' "$ts" "$rand" "$ext")
-
-scp -q "$1" "temp.causal.agency:/usr/local/www/$url"
-
-echo "https://$url"
-type pbcopy > /dev/null && printf "https://$url" | pbcopy