From cb75d85e2a26c06e007a4c9e3454e0bbe3fab623 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Mon, 18 Nov 2024 03:14:33 +0100 Subject: [PATCH] Add simple history stack / "up" command Felt the need for a late night hack :) --- gc | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/gc b/gc index 8cac28d..aa84de2 100755 --- 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 < "$HISTORY" if ! tty >/dev/null; then catlike @@ -88,4 +96,4 @@ else ui fi -rm -f "$LINKS" +rm -f "$LINKS" "$HISTORY" -- libgit2 1.8.1