From: Case Duckworth Date: Sat, 30 May 2020 19:35:17 +0000 (-0500) Subject: Change some functions to only Bash X-Git-Tag: 0.2~6 X-Git-Url: https://reisub.nsupdate.info/git/?p=bollux.git%2F.git;a=commitdiff_plain;h=eccddbfc39fd48a3efca74e2370c854806deef6c Change some functions to only Bash --- diff --git a/bollux b/bollux index 0686c21..87c35fb 100755 --- a/bollux +++ b/bollux @@ -9,6 +9,8 @@ PRGN="${0##*/}" VRSN=0.1 # State REDIRECTS=0 +# Bash options +# shopt -s extglob bollux_usage() { cat < NAME[...] local name="$1" local string="$2" + # shopt -u extglob # TODO port re ^ to extglob syntax local re='^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?' [[ $string =~ $re ]] || return $? + # shopt -s extglob local scheme="${BASH_REMATCH[2]}" local authority="${BASH_REMATCH[4]}" @@ -250,10 +261,10 @@ parse_url() { # eval "$(split_url NAME STRING)" => NAME[...] for c in scheme authority query fragment; do [[ "${!c}" ]] && - printf '%s[%s]=%q\n' "$name" "$c" "${!c}" + run printf '%s[%s]=%q\n' "$name" "$c" "${!c}" done # unclear if the path is always set even if empty but it looks that way - printf '%s[path]=%q\n' "$name" "$path" + run printf '%s[path]=%q\n' "$name" "$path" } # is a NAME defined ('set' in bash)? @@ -289,6 +300,7 @@ handle_response() { REDIRECTS=0 BOLLUX_URL="$URL" run prompt "$meta" QUERY + # shellcheck disable=2153 run blastoff "?$QUERY" ;; 2*) @@ -323,10 +335,13 @@ handle_response() { display() { case "$1" in *\;*) - mime="$(cut -d\; -f1 <<<"$1" | trim)" - charset="$(cut -d\; -f2 <<<"$1" | trim)" + mime="${1%;*}" + charset="${1#*;}" + trim "$mime" + trim "$charset" + log d "$mime $charset" ;; - *) mime="$(trim <<<"$1")" ;; + *) mime="$(trim "$1")" ;; esac [[ -z "$mime" ]] && mime="text/gemini" @@ -384,7 +399,9 @@ mklesskey() { } normalize_crlf() { - gawk 'BEGIN{RS="\n\n"}{gsub(/\r\n?/,"\n");print;print ""}' + while read -r line; do + printf '%s\n' "${line//$'\r'?($'\n')/}" + done } typeset_gemini() {