bopher-ng

A better Gopher client in pure Bash
git clone git://git.luxferre.top/bopher-ng.git
Log | Files | Refs | README | LICENSE

commit 8060459dc777d69a22fdf0a7694b1d9c03265787
parent aa3a2522037842c627b4e994fb8c42b549b37b72
Author: Luxferre <lux@ferre>
Date:   Mon,  3 Apr 2023 21:37:12 +0300

Improved gmi2map logic

Diffstat:
Mtools/README-tools.md | 18+++++++++---------
Mtools/gmi2map.sh | 5++++-
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/tools/README-tools.md b/tools/README-tools.md @@ -73,7 +73,7 @@ Note that by default, reflow logic in `gmi2map.sh` is optional and you have to s cat [file] | gmi2map.sh [page_width] [leading_spaces] [trailing_spaces] [placeholder_char] ``` -I.e. it looks like the `phlow.sh` and `gopherinfo.sh` options combined, but the spaces part only applies to the reflow, which is also off by default. +I.e. it looks like the `phlow.sh` and `gopherinfo.sh` options combined, but the spaces part only applies to the reflow, which is also off by default. Also, it doesn't align the whitespaces after the infolines unless there is non-zero amount of trailing spaces. Example - imagine we have this rudimentary Gemtext document in the `example.gmi` file: ``` @@ -87,19 +87,19 @@ I write a bit longer Gemtext here to showcase reflow capabilities of Bopher Tool See ya! ``` -When running `cat example.gmi | bash gmi2map.sh 67`, this file translates to the following Gophermap: +When running `cat example.gmi | bash gmi2map.sh 67 0 1`, this file translates to the following Gophermap: ``` $ cat example.gmi | bash gmi2map.sh 67 -iI write short Gemtext here. ; ; 0 -i ; ; 0 -iI write a bit longer Gemtext here to showcase reflow capabilities ; ; 0 -iof Bopher Tools' gmi2map.sh script, because it really is cool. ; ; 0 -i ; ; 0 +iI write short Gemtext here. ; ; 0 +i ; ; 0 +iI write a bit longer Gemtext here to showcase reflow capabilities ; ; 0 +iof Bopher Tools' gmi2map.sh script, because it really is cool. ; ; 0 +i ; ; 0 1Anyway, why not publish it on Gopher? luxferre happynetbox.com 79 hOr read my blog on Web... URL:https://chronovir.us ; 0 -i ; ; 0 -iSee ya! ; ; 0 +i ; ; 0 +iSee ya! ; ; 0 . ``` diff --git a/tools/gmi2map.sh b/tools/gmi2map.sh @@ -22,8 +22,11 @@ CRLF=$'\r\n' [[ -z "$TSPACES" ]] && TSPACES=0 [[ -z "$DELIM" ]] && DELIM=';' +FORMAT_WIDTH=0 # make formatting width distinct from the target reflow width +(( TSPACES > 0 )) && FORMAT_WIDTH="$TARGET_WIDTH" # and only use it if there are trailing spaces + # format strings to use in different situations: -reflowfmt="%-$(( LSPACES ))s%-${TARGET_WIDTH}s%-$(( TSPACES ))s\n" # params: smth, line, smth +reflowfmt="%-$(( LSPACES ))s%-${FORMAT_WIDTH}s%-$(( TSPACES ))s\n" # params: smth, line, smth infofmt="i%s${TAB}%s${TAB}%s${TAB}0${CRLF}" # params: line, DELIM, DELIM gopherlinkfmt="%s%s${TAB}%s${TAB}%s${TAB}%d${CRLF}" # params: type, name, selector, host, port extlinkfmt="h%s${TAB}URL:%s${TAB}%s${TAB}0${CRLF}" # params: name, URL, DELIM