From d3d4b4c3a2162b45f387f0d28f995afcadb47eba Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Sat, 13 Nov 2021 11:26:25 -0500 Subject: [PATCH] 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) --- README | 5 +++++ gc | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 README create mode 100755 gc diff --git a/README b/README new file mode 100644 index 0000000..3a0039a --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +# gc + +A simple gopher client. + +Written for the lulz and learnings. diff --git a/gc b/gc new file mode 100755 index 0000000..8f204d1 --- /dev/null +++ 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 -- libgit2 1.1.1