-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: geminiclient action: commit revision: path_from: revision_from: 2088909419fd5edb53d5eda9c9920b982f94b8a0: path_to: revision_to:
commit 2088909419fd5edb53d5eda9c9920b982f94b8a0 Author: epoch <epoch@hacking.allowed.org> Date: Sun Jun 7 07:35:07 2020 -0500 not complete shit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..3c2815562e8972f4b79fb71d641305152c4bb986 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +install: + install -t $(PREFIX)/bin gemini2terminal + install -t $(PREFIX)/bin gemini diff --git a/gemini b/gemini new file mode 100755 index 0000000000000000000000000000000000000000..f4b4629fae7fdf6c4310a7b071cf6edb4a361c2b --- /dev/null +++ b/gemini @@ -0,0 +1,52 @@ +#!/bin/sh + +if [ "$#" -lt 3 ];then + printf "usage: URI domain port\n" + exit 1 +fi + +export gemini_uri="$1" +uri="$1" +host="$2" +port="$3" +path="$4" + +echo "args: $@" >&2 + +if [ "$3" = "" ];then + port=1965 +else + port=$3 +fi + +mkdir -p "${PREFIX}/var/cache/gemini" + +cachename="${PREFIX}/var/cache/gemini/$(printf "%s\n" "$uri" | tr '\n' '\0' | xargs -0 uriescape | sed 's|/|%2f|g' | sed 's|?|%3f|g')" + +#if [ ! -e "$cachename" ];then #if the cache doesn't exist, make it. + printf '%s\r\n' "$uri" | ncat --no-shutdown --ssl "$host" "$port" > "$cachename" +#fi +#cat "$cachename" +code="$(head -n1 "$cachename" | tr -d '\r' | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f1)" +meta="$(head -n1 "$cachename" | tr -d '\r' | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)" +mimetype +while [ "$code" = 10 ];do + query="$(uriescape "$(echo | dmenu -p "$meta")" | sed 's|?|%3f|g')" + if [ ! "$query" ];then #don't bother sending an empty query + exit 1 + fi + ## update the URI with the query string... + uri="${uri}?${query}" + cachename="${PREFIX}/var/cache/gemini/$(printf "%s\n" "$uri" | tr '\n' '\0' | xargs -0 uriescape | sed 's|/|%2f|g' | sed 's|?|%3f|g')" + ## re-send the request... + printf '%s\r\n' "$uri" | ncat --no-shutdown --ssl "$host" "$port" > "$cachename" + code="$(head -n1 "$cachename" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f1)" + mimetype="$(head -n1 "$cachename" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)" +done +if [ "$code" != 20 ];then + xmessage "gemini failed for some reason. file: $cachename code: $(head -n1 "$cachename") $code" + exit 1 +fi +mimetype="$(printf "%s\n" "$meta" | tr ';' ' ' | cut '-d ' -f1)" +uristart "$(printf "file://%s?mime-type=%s\n" "$cachename" "$mimetype")" +rm "$cachename" #ha. who needs cache? diff --git a/gemini2terminal b/gemini2terminal new file mode 100755 index 0000000000000000000000000000000000000000..0346b2aae2f4de8178f6cb432e8c3d812e8ff884 --- /dev/null +++ b/gemini2terminal @@ -0,0 +1,30 @@ +#!/bin/sh +printf "client side idea of our URI: <%s>. header: " "$gemini_uri" +domain="$(printf "%s\n" "$gemini_uri" | uricut -d)" +scheme="$(printf "%s\n" "$gemini_uri" | uricut -s)" +path="$(printf "%s\n" "$gemini_uri" | uricut -p)" +#most_of_path="$(dirname -- "$(printf "%s\n" "$gemini_uri" | uricut -p)" | sed 's|^\.||g')" +most_of_path="$(printf "%s\n" "$gemini_uri" | uricut -p | rev | cut -d/ -f2- | rev)" +### to do this... first. +### we convert the fragment ID links to absolutes based on the gemini_uri + +### this is the verbose version. +#sed \ +#'s|^=>[ \t]*\([A-Za-z][A-Za-z+.-]*:[^ \t]*\)|[link] \1 (absolute) \1|g +#s|^=>[ \t]*\(#[^ \t]*\)|[link] \1 (fragmentid_relative) '"${gemini_uri}"'\1|g +#s|^=>[ \t]*\(?[^ \t]*\)|[link] \1 (querystring_relative) '"$scheme"'://'"$domain""$path"'\1|g +#s|^=>[ \t]*\(//[^ \t]*\)|[link] \1 (scheme_relative) '"$scheme"':\1|g +#s|^=>[ \t]*\(/[^ \t]*\)|[link] \1 (absolute_path) '"$scheme"'://'"$domain"'\1|g +#s|^=>[ \t]*\([^ \t]*\)|[link] \1 (same-dir path relative) '"$scheme"'://'"$domain""$most_of_path"'/\1|g +#s|^=>[ \t]*\(.*\)|[link] \1 UNHANDLED \1|g +#s|^* | '"$(printf "•" | html_entities_decode)"'|g' +sed \ +'s|^=>[ \t]*\([A-Za-z][A-Za-z+.-]*:[^ \t]*\)|[link] \1|g +s|^=>[ \t]*\(#[^ \t]*\)|[link] '"${gemini_uri}"'\1|g +s|^=>[ \t]*\(?[^ \t]*\)|[link] '"$scheme"'://'"$domain""$path"'\1|g +s|^=>[ \t]*\(//[^ \t]*\)|[link] '"$scheme"':\1|g +s|^=>[ \t]*\(/[^ \t]*\)|[link] '"$scheme"'://'"$domain"'\1|g +s|^=>[ \t]*\([^ \t]*\)|[link] '"$scheme"'://'"$domain""$most_of_path"'/\1|g +s|^=>[ \t]*\(.*\)|[link] \1 UNHANDLED \1|g +s|^\(##*\) \(.*\)$|\1'"$(printf "\x1b[1m")"'\2'"$(printf "\x1b[0m")"'|g +s|^* | '"$(printf "•" | html_entities_decode)"' |g' diff --git a/mimetype.conf b/mimetype.conf new file mode 100644 index 0000000000000000000000000000000000000000..e5b5ffc9545e4b63ac395f305b5e052902f9df1c --- /dev/null +++ b/mimetype.conf @@ -0,0 +1 @@ +text/gemini: x-terminal-emulator -title "$(uriunescape '%p' | cut -d/ -f8-)" -hold -e sh -c "gemini2terminal < '%p'" diff --git a/uristart.conf b/uristart.conf new file mode 100644 index 0000000000000000000000000000000000000000..8a64fd5a0d21d1cebbdb06408ada75cc566e7107 --- /dev/null +++ b/uristart.conf @@ -0,0 +1 @@ +s gemini: gemini '%U' '%d' '%P' '%p'
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 18:34:47 2024