#!/bin/rc # webshittery for use with the following plumb rule: # data matches (https?|gemini)://[a-zA-Z0-9\-._~:/?#[\]@!$&''()*+,;=%]+|/tmp/webshit/.*|(\[|{)[0-9]+(\]|})|←|•|→|\[formfield\]|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/.+ # plumb start window -hide -scroll -cd $wdir play $data # type matches video/.+ # plumb start window -r 1 294 649 662 -cd $wdir treason $data rfork e nl = ' ' 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 jumpto{ if(test -s $1){ if(~ `{read -c 3 $1} ←){ cat $plumb >/dev/text focus } if not plumb -t `{file -m $1} $1 } if not echo /tmp/webshit/$1 empty or does not exist } fn gemini{ } fn http{ read -c 6000 > incoming mime = `{file -m incoming} switch($mime){ case text/html w = $next($w) >$w{ echo /tmp/webshit/$w ← • → $"plumb^$nl if(~ $plumb(2) -u) # hpost output plumb = $plumb(3) cat incoming /fd/0 | htmlfmt -l 4294967295 -u $plumb } cat $w > /dev/text focus case text/* w = $next($w) >$w{ echo /tmp/webshit/$w ← • → $"plumb^$nl cat incoming /fd/0 } cat $w > /dev/text focus case audio/* # may be a stream, so don't save to disk echo playing $"mime^:^$nl^$prompt(1) window -scroll -hide play $plumb window -scroll -hide play $plumb case * w = $next($w) cat incoming /fd/0 >$w plumb -t `{file -m $plumb} $plumb || echo $mime saved at /tmp/webshit/$w } rm -f incoming } [2]/dev/null}){ plumb = $plumb($#plumb) switch($plumb){ case gemini* tlsclient `{echo $plumb | sed 's,gemini://([^/]+).*,tcp!\1!1965,'} /bin/rc -c 'echo $"plumb^ ; cat >incoming >[2]/dev/null' mime = `{sed 's/ //;1q' incoming} switch($mime(1)){ case 1* # INPUT echo $mime(2-) plumb $plumb'?'`{ { echo holdon >[1=3] sed 's/ /%20/g' /dev/cons | urlencode }>[3]/dev/consctl } case 2* # SUCCESS cat incoming case 3* # REDIRECT echo redirect... plumb $mime(2) case * # ERRORS echo gemini error: $mime } rm -f incoming case http* plumb = `{hget -l $plumb} hget $plumb | http case '[formfield]' plumb = `{sed 's,.*(https?://[^ '']+).*,\1,;q' /dev/text} hpost $"plumb | sed 's/.*/{&}/' case hpost* rc -c $"plumb | http case '['* '{'* plumb = `{sed -n '/^\'^$plumb^' ?[a-z]+:\/\//{s/^.[0-9]+. ?//p;q;}' /dev/text} if(~ $#plumb 1) 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/* jumpto `{basename $plumb} 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 } }