From b73e5bf3e08885a0c2c5c2d0daa5d489800fd112 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 3 Jun 2020 23:22:55 -0500 Subject: Version bump --- README.md | 2 +- bollux | 58 ++++++++++++++++++++++++++-------------------------------- bollux.1 | 2 +- bollux.conf.5 | 2 +- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 07b4252..03131b3 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ $ cd bollux ## Alternative ``` -$ curl -fLo bollux https://git.sr.ht/~acdw/bollux/blob/0.2.2/bollux +$ curl -fLo bollux https://git.sr.ht/~acdw/bollux/blob/0.3.0/bollux $ chmod +x bollux $ ./bollux ``` diff --git a/bollux b/bollux index b6fb2a5..c8a6175 100755 --- a/bollux +++ b/bollux @@ -2,11 +2,11 @@ # bollux: a bash gemini client # Author: Case Duckworth # License: MIT -# Version: 0.2.2 +# Version: 0.3 # Program information PRGN="${0##*/}" -VRSN=0.2.2 +VRSN=0.3 # State REDIRECTS=0 set -f @@ -49,11 +49,11 @@ trim() { log() { [[ "$BOLLUX_LOGLEVEL" == QUIET ]] && return case "$1" in - d* | D*) # debug + [dD]*) # debug [[ "$BOLLUX_LOGLEVEL" == DEBUG ]] || return fmt=34 ;; - e* | E*) # error + [eE]*) # error fmt=31 ;; *) fmt=1 ;; @@ -68,7 +68,7 @@ bollux() { run bollux_args "$@" run history_init - if [[ ! "${BOLLUX_URL:+isset}" ]]; then + if [[ ! "${BOLLUX_URL:+x}" ]]; then run prompt GO BOLLUX_URL fi @@ -173,6 +173,7 @@ blastoff() { # load a url log d "URL='$URL' server='$server'" run request_url "$server" "$BOLLUX_PORT" "$URL" | + run normalize_crlf | run handle_response "$URL" } @@ -318,29 +319,22 @@ request_url() { ssl_cmd_tls1_3=("${ssl_cmd[@]}" -tls1_3) # always try to connect with TLS v1.3 first - run "${ssl_cmd_tls1_3[@]}" <<<"$url" 2>/dev/null || run "${ssl_cmd_tls1_2[@]}" <<<"$url" 2>/dev/null + run "${ssl_cmd_tls1_3[@]}" <<<"$url" 2>/dev/null || + run "${ssl_cmd_tls1_2[@]}" <<<"$url" 2>/dev/null } handle_response() { local URL="$1" code meta - while read -r -d $'\r' hdr; do - code="$(gawk '{print $1}' <<<"$hdr")" - meta="$( - gawk '{for(i=2;i<=NF;i++)printf "%s ",$i;printf "\n"}' <<<"$hdr" - )" - break - done - - log x "[$code] $meta" + read -r code meta + log d "[$code] $meta" case "$code" in 1*) REDIRECTS=0 run history_append "$URL" "$meta" - run prompt "$meta" QUERY - # shellcheck disable=2153 - run blastoff "?$QUERY" + run prompt "$meta" + run blastoff "?$REPLY" ;; 2*) REDIRECTS=0 @@ -370,15 +364,15 @@ handle_response() { ;; 4*) REDIRECTS=0 - die "$((100 + code))" "$code" + die "$((100 + code))" "Temporary error: $code" ;; 5*) REDIRECTS=0 - die "$((100 + code))" "$code" + die "$((100 + code))" "Permanent error: $code" ;; 6*) REDIRECTS=0 - die "$((100 + code))" "$code" + die "$((100 + code))" "Certificate error: $code" ;; *) [[ -z "${code-}" ]] && die 100 "Empty response code." @@ -390,7 +384,7 @@ handle_response() { display() { # split header line local -a hdr - local i + local i mime charset h IFS=$'\n' read -d "" -ra hdr <<<"${1//;/$'\n'}" mime="$(trim "${hdr[0],,}")" @@ -398,6 +392,7 @@ display() { h="$(trim "${hdr[$i]}")" case "$h" in charset=*) charset="${h#charset=}" ;; + # add mime-extensions here esac done @@ -423,8 +418,7 @@ display() { if declare -F | grep -q "$submime"; then log d "typeset_$submime" { - normalize_crlf | - iconv -f "${charset^^}" -t "UTF-8" | + iconv -f "${charset^^}" -t "UTF-8" | tee "$BOLLUX_PAGESRC" | run "typeset_$submime" | run "${less_cmd[@]}" && bollux_quit @@ -432,8 +426,7 @@ display() { else log "cat" { - normalize_crlf | - iconv -f "${charset^^}" -t "UTF-8" | + iconv -f "${charset^^}" -t "UTF-8" | tee "$BOLLUX_PAGESRC" | run "${less_cmd[@]}" && bollux_quit } || run handle_keypress "$?" @@ -495,12 +488,12 @@ typeset_gemini() { fi continue ;; - =\>*) + '=>'*) : $((ln += 1)) gemini_link "$REPLY" $pre "$ln" ;; - \#*) gemini_header "$REPLY" $pre ;; - \**) + '#'*) gemini_header "$REPLY" $pre ;; + '*'*) if [[ "$REPLY" =~ ^\*[[:space:]]+ ]]; then gemini_list "$REPLY" $pre else @@ -643,18 +636,19 @@ handle_keypress() { select_url() { run mapfile -t < <(extract_links <"$1") + PS3="OPEN> " select u in "${MAPFILE[@]}"; do case "$REPLY" in q) bollux_quit ;; esac - run blastoff "$(gawk '{print $1}' <<<"$u")" && break + run blastoff "${u%%[[:space:]]*}" && break done [[:space:]]*([^[:space:]]+)([[:space:]]+(.*))?$ ]]; then + while read -r; do + if [[ "$REPLY" =~ ^=\>[[:space:]]*([^[:space:]]+)([[:space:]]+(.*))?$ ]]; then url="${BASH_REMATCH[1]}" alt="${BASH_REMATCH[3]}" diff --git a/bollux.1 b/bollux.1 index 08a8d82..4b6948d 100644 --- a/bollux.1 +++ b/bollux.1 @@ -1,4 +1,4 @@ -.TH bollux 1 0.2.2 +.TH bollux 1 0.3.0 .SH NAME bollux \- gemini protocol browser written in bash(1) .SH SYNOPSIS diff --git a/bollux.conf.5 b/bollux.conf.5 index eecaff0..9cee1b5 100644 --- a/bollux.conf.5 +++ b/bollux.conf.5 @@ -1,4 +1,4 @@ -.TH bollux.conf 5 0.2.2 +.TH bollux.conf 5 0.3.0 .SH NAME .B bollux.conf \- configuration file for -- cgit 1.4.1-21-gabe81