gc

simple gopher client
git clone git://git.alexkarle.com.com/gc
Log | Files | Refs | README | LICENSE

commit cb75d85e2a26c06e007a4c9e3454e0bbe3fab623 (patch)
parent cd7fdfa66369ccbbaa9e60979d68103d498808fd
Author: Alex Karle <alex@alexkarle.com>
Date:   Mon, 18 Nov 2024 03:14:33 +0100

Add simple history stack / "up" command

Felt the need for a late night hack :)

Diffstat:
Mgc | 32++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/gc b/gc @@ -40,22 +40,24 @@ catlike() { goto() { printf "goto> " read -r URL + echo "$URL" >> "$HISTORY" +} + +goback() { + sed -i '$d' "$HISTORY" + URL=$(tail -n 1 "$HISTORY") } graburl() { N="$1" link=$(grep "^\[$N\]:" "$LINKS") URL=${link##\[*\]: } + echo "$URL" >> "$HISTORY" } ui() { while [ -n "$URL" ]; do - parseurl - 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 + catlike URL="" while true; do @@ -65,12 +67,16 @@ ui() { [0-9]*) graburl "$opt" && if [ -n "$URL" ]; then break; else echo "no such link"; fi ;; l*) cat "$LINKS" ;; g*) goto ; break ;; + u*) goback ; break ;; + H*) cat "$HISTORY" ;; h*) cat <<EOM ;; -NUM -- go to this target -g[oto] -- specify new URL -h[elp] -- print this message -l[ist] -- list targets -q[uit] -- quit +NUM -- go to this target +g[oto] -- specify new URL +u[p] -- go up a directory +H[istory] -- list the history +h[elp] -- print this message +l[ist] -- list targets +q[uit] -- quit EOM q*) break;; *) echo "no such command; 'h' for help, 'q' to quit" ;; @@ -81,6 +87,8 @@ EOM URL=$1 LINKS=$(mktemp) +HISTORY=$(mktemp) +echo "$URL" > "$HISTORY" if ! tty >/dev/null; then catlike @@ -88,4 +96,4 @@ else ui fi -rm -f "$LINKS" +rm -f "$LINKS" "$HISTORY"