diff options
author | Case Duckworth | 2020-05-22 18:56:28 -0500 |
---|---|---|
committer | Case Duckworth | 2020-05-22 18:56:28 -0500 |
commit | eaa28da3af6afbadbd2c252426e9d8de25bc142a (patch) | |
tree | 0b9e70578e838ed9bfaa92bdbf0399c07efbe859 | |
parent | Bump version (diff) | |
download | bollux-eaa28da3af6afbadbd2c252426e9d8de25bc142a.tar.gz bollux-eaa28da3af6afbadbd2c252426e9d8de25bc142a.zip |
Statify URL and require things
-rwxr-xr-x | bollux | 28 |
1 files 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!!!"; } | |||
82 | # example.com => gemini://example.com/ | 82 | # example.com => gemini://example.com/ |
83 | _address() { # _address URL | 83 | _address() { # _address URL |
84 | addr="$1" | 84 | addr="$1" |
85 | |||
85 | [[ "$addr" != *://* ]] && addr="$PROT://$addr" | 86 | [[ "$addr" != *://* ]] && addr="$PROT://$addr" |
86 | trim <<<"$addr" | 87 | trim <<<"$addr" |
87 | } | 88 | } |
@@ -127,9 +128,7 @@ request() { # request [-s SERVER] URL | |||
127 | 128 | ||
128 | # handle the response | 129 | # handle the response |
129 | # cf. gemini://gemini.circumlunar.space/docs/spec-spec.txt | 130 | # cf. gemini://gemini.circumlunar.space/docs/spec-spec.txt |
130 | handle() { # handle URL < RESPONSE | 131 | handle() { # handle < RESPONSE ## needs $URL in state |
131 | url="$(_address "$1")" | ||
132 | |||
133 | head="$(sed 1q)" | 132 | head="$(sed 1q)" |
134 | code="$(awk '{print $1}' <<<"$head")" | 133 | code="$(awk '{print $1}' <<<"$head")" |
135 | meta="$(awk '{for(i=2;i<=NF;i++)printf "%s ",$i;printf "\n"}' <<<"$head")" | 134 | meta="$(awk '{for(i=2;i<=NF;i++)printf "%s ",$i;printf "\n"}' <<<"$head")" |
@@ -141,7 +140,7 @@ handle() { # handle URL < RESPONSE | |||
141 | log 3 "Input" | 140 | log 3 "Input" |
142 | put "$meta" | 141 | put "$meta" |
143 | read -rep "? " | 142 | read -rep "? " |
144 | bollux "$url?$REPLY" | 143 | bollux "$URL?$REPLY" |
145 | ;; | 144 | ;; |
146 | 2*) # SUCCESS | 145 | 2*) # SUCCESS |
147 | log 3 "Success" | 146 | log 3 "Success" |
@@ -209,7 +208,8 @@ display() { # display MIMETYPE < DOCUMENT | |||
209 | case "$mimetype" in | 208 | case "$mimetype" in |
210 | text/*) | 209 | text/*) |
211 | # normalize line endings to "\n" | 210 | # normalize line endings to "\n" |
212 | awk 'BEGIN{RS=""}{gsub("\r\n?","\n");print}' | 211 | # awk 'BEGIN{RS=""}{gsub(/\r\n?/,"\n");print}' |
212 | cat | ||
213 | # TODO: use less with linking and stuff | 213 | # TODO: use less with linking and stuff |
214 | # less -R -p'^=>' +g | 214 | # less -R -p'^=>' +g |
215 | # lesskey: | 215 | # lesskey: |
@@ -225,7 +225,7 @@ display() { # display MIMETYPE < DOCUMENT | |||
225 | *) | 225 | *) |
226 | tn="$(mktemp)" | 226 | tn="$(mktemp)" |
227 | dd status=progress >"$tn" | 227 | dd status=progress >"$tn" |
228 | fn="$DLDR/${url##*/}" | 228 | fn="$DLDR/${URL##*/}" |
229 | if [[ -f "$fn" ]]; then | 229 | if [[ -f "$fn" ]]; then |
230 | log - "Saved '$tn'." | 230 | log - "Saved '$tn'." |
231 | else | 231 | else |
@@ -242,21 +242,25 @@ display() { # display MIMETYPE < DOCUMENT | |||
242 | ### main entry point ### | 242 | ### main entry point ### |
243 | bollux() { | 243 | bollux() { |
244 | if (($# == 1)); then | 244 | if (($# == 1)); then |
245 | url="$1" | 245 | URL="$1" |
246 | else | 246 | else |
247 | read -rp "GO> " url | 247 | read -rp "GO> " URL |
248 | fi | 248 | fi |
249 | 249 | ||
250 | log 5 "url : $url" | 250 | log 5 "URL : $URL" |
251 | log 5 "addr: $(_address "$url")" | 251 | log 5 "addr: $(_address "$URL")" |
252 | log 5 "serv: $(_server "$url")" | 252 | log 5 "serv: $(_server "$URL")" |
253 | 253 | ||
254 | request "$url" | handle "$url" | 254 | request "$URL" | handle |
255 | } | 255 | } |
256 | 256 | ||
257 | if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then | 257 | if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then |
258 | # requirements here -- so they're only checked once | 258 | # requirements here -- so they're only checked once |
259 | require awk | ||
260 | require dd | ||
261 | require mv | ||
259 | require openssl | 262 | require openssl |
263 | require sed | ||
260 | 264 | ||
261 | bollux "$@" | 265 | bollux "$@" |
262 | fi | 266 | fi |