#!/bin/rc # webshittery for use with the following plumb rule: # data matches (gemini|gopher|https?)://.+|/tmp/webshit/.*|[^}]*[⁰¹²³⁴⁵⁶⁷⁸⁹]+|←|•|→|\[submit\]|hpost.* # plumb to web # plumb client window webshit # and to handle mimetypes other than text/*, something like: # type matches image/.+|application/(troff|postscript|pdf|ghostscript) # plumb to image # plumb client window -r 0 0 9000 9000 page -i # type matches audio/.+ # arg isfile $data # plumb start window -hide -scroll play $file # type matches video/.+ # arg isfile $data # plumb start window -r 0 0 9000 9000 treason $file rfork e nl = ' ' width = 70 next = `{seq -w 02 99; echo 01} prev = `{echo 99; seq -w 01 98} mkdir -p /tmp/webshit cd /tmp/webshit w = `{ls -t | sed 1q} if(! ~ $w $next) w = $#next label webshit echo scroll >/dev/wctl fn focus{ echo unhide >/dev/wctl >[2]/dev/null echo current >/dev/wctl if(test -f /dev/kbdin) echo -n  >/dev/kbdin } fn format{ if(test -s incoming){ w = $next($w) if(~ $mime text/*){ if(~ $plumb *' '*) echo ← • → /tmp/webshit/$w '{'^$"plumb^'}'^$nl >$w if not echo ← • → /tmp/webshit/$w $plumb^$nl >$w switch($mime){ case text/gemini* tr -d [ ]/{ sub(/^=>[ ]+/, "") if(match($1, "^//")) url[n] = "gemini:"$1 else if(match($1, "^/")) url[n] = root $1 else if(match($1, "^[a-z]+://")) url[n] = $1 else url[n] = base $1 sub(/^[^ ]+[ ]+/, "") sub(/$/, fn(n++)) } {print} END{ if(n == 1) exit printf "\nReferences:\n" for(i = 1; i < n; i++) printf "%s%s\n", fn(i), url[i] } ' | fmt -j -l $width >>$w case text/gopher* tr -d 1{ type = substr($1, 1, 1) display = substr($1, 2, length($1) - 1) if(type == "i" || type == "3") print display else if(type == "h"){ sub("^URL:", "", $2) url[n] = $2 print "HTTP: " display fn(n++) }else{ if($3 == "") s = host else s = $3 if($4 != "" && $4 != "70") s = s ":" $4 if($4 == "" && s == host && ENVIRON["port"] != "70") s = s ":" ENVIRON["port"] if(substr($2, 1, 1) == "/") url[n] = "gopher://" s "/" type $2 else url[n] = "gopher://" s "/" type base $2 print t[type] display fn(n++) } } END{ if(n == 1) exit printf "References:\n" for(i = 1; i < n; i++) printf "%s%s\n", fn(i), url[i] } ' >>$w case text/html* if(~ $plumb(2) -u) # hpost output plumb = $plumb(3) htmlfmt -u $plumb -l $width incoming >>$w case * tr -d >$w } cat $w >/dev/text focus } if not{ mv incoming $w plumb -t $mime $w || echo $mime saved at /tmp/webshit/$w } } rm -f incoming } fn gemget{ echo $plumb^ reply = `{read | tr -d } switch($reply(1)){ case 1* echo $reply(2-) >/dev/text focus echo -n input: $plumb^'?' >[1=3] >/dev/consctl{ echo holdon sed 's/ /%20/g' /dev/cons | urlencode | sed 's/%0A$//' >[1=3] } case 2* cat >incoming >[2]/dev/null echo $reply(2) | tr -d >[1=3] case 3* # REDIRECT echo redirect: $reply(2) | tr -d >[1=3] case * # ERRORS echo error: $reply(2-) >[1=3] } } [2]/dev/null}){ plumb = $plumb($#plumb) switch($plumb){ case gemini://?* gopher://?* https://?* http://?* proto = `{echo $plumb | sed 's,([^:]+).*,\1,'} host = `{echo $plumb | sed 's,[^:]+://([^:/]+).*,\1,'} port = `{echo $plumb | sed 's,[^:]+://[^:/]+:([0-9]+).*,\1,'} if(! ~ $port [0-9]*) port = $proto switch($proto){ case gemini if(~ $port gemini) port = 1965 mime = `{tlsclient tcp!$host!$port /bin/rc -c gemget >[3=1] >[2]/dev/null} switch($mime(1)){ case input: redirect: plumb $mime(2) || echo plumb $mime(2) failed case error: echo $mime case * format } case gopher if(~ $port gopher) port = 70 host = `{ndb/dnsgetip $host} item = `{echo $plumb | sed 's!^gopher://[^/]+/(.)/.*!\1!'} if(! ~ $item ?) item = 1 what = `{echo $plumb | sed 's!^gopher://[^/]+(/./|/)?(.*)!/\2!'} if(~ $item 7){ focus echo Enter search string: >/dev/text >/dev/consctl{ echo holdon what = $what^' '^`''{read /dev/cons} } } $con/ctl echo $what^ > $con/data cat $con/data }>incoming if(~ $item 1 7) mime = text/gopher if not mime = `{file -m incoming} format case http* <>/mnt/web/clone { d=/mnt/web/^`{sed 1q} echo -n url $plumb >[1=0] cat $d/body >incoming plumb = `{cat $d/parsed/url} mime = `{cat $d/contenttype >[2]/dev/null} } if(~ $mime '') mime = `{file -m incoming} format } case '[submit]' plumb = `{sed 's,.*(https?://[^ '']+).*,\1,;q' /dev/text} hpost $"plumb | sed 's/.*/{&}/' case hpost* rc -c $"plumb >incoming mime = `{file -m incoming} format case *[⁰¹²³⁴⁵⁶⁷⁸⁹] plumb = `{echo $plumb | tr -dc ⁰¹²³⁴⁵⁶⁷⁸⁹} plumb = `{sed -n '/^'^$plumb^'[a-z]+:\/\//{s/^[⁰¹²³⁴⁵⁶⁷⁸⁹]+//p;q;}' /dev/text} plumb $"plumb case ← plumb = `{sed 's,.*/tmp/webshit/([0-9]+).*,\1,;q' /dev/text} if(~ $plumb $prev){ i = $prev($plumb) while(! ~ $i $plumb && ! ~ `{file -m $i} text/*) i = $prev($i) cat $i >/dev/text focus } case → plumb = `{sed 's,.*/tmp/webshit/([0-9]+).*,\1,;q' /dev/text} if(~ $plumb $next){ i = $next($plumb) while(! ~ $i $plumb && ! ~ `{file -m $i} text/*) i = $next($i) cat $i >/dev/text focus } case /tmp/webshit/* if(test -s $plumb){ if(~ `{read -c 3 $plumb} ←){ cat $plumb >/dev/text focus } if not plumb -t `{file -m $plumb} $plumb } if not echo $plumb empty or does not exist case • >/dev/text for(i in `{ls -t}){ if(~ `{read -c 3 $i} ←) sed 1q $i if not echo /tmp/webshit/$i `{file -m $i} } focus } }