Statify URL and require things

This commit is contained in:
Case Duckworth 2020-05-22 18:56:28 -05:00
parent fa65687de5
commit eaa28da3af
1 changed files with 16 additions and 12 deletions

28
bollux
View File

@ -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