summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-12 16:45:22 -0500
committerJune McEnroe <june@causal.agency>2019-02-12 16:45:22 -0500
commite6c20f61387a85a5b15a79b5474f710e5878c6b3 (patch)
tree09f679c946641b22b96e96046e57d6eaad82f372 /bin
parentUse a proper fread-realloc loop in hi (diff)
downloadsrc-e6c20f61387a85a5b15a79b5474f710e5878c6b3.tar.gz
src-e6c20f61387a85a5b15a79b5474f710e5878c6b3.zip
Unify *up scripts into one up.sh
Diffstat (limited to 'bin')
-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
6 files changed, 133 insertions, 2 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"