From eaa28da3af6afbadbd2c252426e9d8de25bc142a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 22 May 2020 18:56:28 -0500 Subject: Statify URL and require things --- bollux | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/bollux b/bollux index 9934dab..77f7c11 100755 --- a/bollux +++ b/bollux @@ -82,6 +82,7 @@ NOT_FULLY_IMPLEMENTED() { log 1 "NOT FULLY IMPLEMENTED!!!"; } # example.com => gemini://example.com/ _address() { # _address URL addr="$1" + [[ "$addr" != *://* ]] && addr="$PROT://$addr" trim <<<"$addr" } @@ -127,9 +128,7 @@ request() { # request [-s SERVER] URL # handle the response # cf. gemini://gemini.circumlunar.space/docs/spec-spec.txt -handle() { # handle URL < RESPONSE - url="$(_address "$1")" - +handle() { # handle < RESPONSE ## needs $URL in state head="$(sed 1q)" code="$(awk '{print $1}' <<<"$head")" meta="$(awk '{for(i=2;i<=NF;i++)printf "%s ",$i;printf "\n"}' <<<"$head")" @@ -141,7 +140,7 @@ handle() { # handle URL < RESPONSE log 3 "Input" put "$meta" read -rep "? " - bollux "$url?$REPLY" + bollux "$URL?$REPLY" ;; 2*) # SUCCESS log 3 "Success" @@ -209,7 +208,8 @@ display() { # display MIMETYPE < DOCUMENT case "$mimetype" in text/*) # normalize line endings to "\n" - awk 'BEGIN{RS=""}{gsub("\r\n?","\n");print}' + # awk 'BEGIN{RS=""}{gsub(/\r\n?/,"\n");print}' + cat # TODO: use less with linking and stuff # less -R -p'^=>' +g # lesskey: @@ -225,7 +225,7 @@ display() { # display MIMETYPE < DOCUMENT *) tn="$(mktemp)" dd status=progress >"$tn" - fn="$DLDR/${url##*/}" + fn="$DLDR/${URL##*/}" if [[ -f "$fn" ]]; then log - "Saved '$tn'." else @@ -242,21 +242,25 @@ display() { # display MIMETYPE < DOCUMENT ### main entry point ### bollux() { if (($# == 1)); then - url="$1" + URL="$1" else - read -rp "GO> " url + read -rp "GO> " URL fi - log 5 "url : $url" - log 5 "addr: $(_address "$url")" - log 5 "serv: $(_server "$url")" + log 5 "URL : $URL" + log 5 "addr: $(_address "$URL")" + log 5 "serv: $(_server "$URL")" - request "$url" | handle "$url" + request "$URL" | handle } if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then # requirements here -- so they're only checked once + require awk + require dd + require mv require openssl + require sed bollux "$@" fi -- cgit 1.4.1-21-gabe81