commit d3d4b4c3a2162b45f387f0d28f995afcadb47eba (patch)
Author: Alex Karle <alex@alexkarle.com>
Date: Sat, 13 Nov 2021 11:26:25 -0500
Initial commit
So far, we have support for menus and plaintext--I'd say its coming
along pretty well!
TODO:
* Interactive loop
* Man page
* Support for other types (h, specifically)
Diffstat:
A | README | | | 5 | +++++ |
A | gc | | | 33 | +++++++++++++++++++++++++++++++++ |
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/README b/README
@@ -0,0 +1,5 @@
+# gc
+
+A simple gopher client.
+
+Written for the lulz and learnings.
diff --git a/gc b/gc
@@ -0,0 +1,33 @@
+#!/bin/sh
+# gc -- gopher client
+die() {
+ echo "$*" 1>&2
+ exit 1
+}
+
+[ -z "$1" ] && die "usage: gc URL"
+
+pretty() {
+ awk -F" " '
+/^[^01i\.]/ { sub("^.", "", $1); printf " ???| %s\n", $1 }
+/^i/ { sub("^i", "", $1); printf " | %s\n", $1 }
+/^0/ { sub("^0", "", $1); links[n++] = sprintf("%s/0%s", $3, $2); printf "%2d TXT| %s\n", n, $1 }
+/^1/ { sub("^1", "", $1); links[n++] = sprintf("%s/1%s", $3, $2); printf "%2d DIR| %s\n", n, $1 }
+END {
+ printf "\n"
+ for (i=0; i < length(links); i++) {
+ printf "[%d]: %s\n", i, links[i]
+ }
+}
+'
+}
+
+uri=${1##gopher://}
+HOST=${uri%%/*}
+TARGET=${uri##$HOST}
+
+case $TARGET in
+ /0/*) echo "${TARGET##/0}" | nc "$HOST" 70 | ${PAGER:-less} ;;
+ /1/*) echo "${TARGET##/1}" | nc "$HOST" 70 | pretty ;;
+ *) echo "$TARGET" | nc "$HOST" 70 | pretty ;; # TODO: handle other types?
+esac