8.9 KiB
Bopher Tools: a set of simple Bash scripts to not just browse Gopher but also create content for it
Bopher Tools is a small collection of simple shell scripts that:
- are written in pure Bash with no external dependencies;
- are totally independent from each other (but can be combined in the true spirit of Unix philosophy);
- only accept input from stdin and only output their results into stdout;
- aim to ease your life when it comes to creating and publishing your own content in Gopherspace.
It is recommended to distribute these scripts along with the main Bopher-NG client, although everyone is free to redistribute them in any other form. Just like the main Bopher-NG script, all these tools are released into public domain. Their documentation is added to this page in the chronological order they were created.
Without further ado, let's begin!
gopherinfo.sh
This tool converts every line of the standard input into a valid CRLF-terminated Gophermap line of the i type that obeys RFC1436. It accepts three optional parameters: the number of leading spaces (0 by default), the number of trailing spaces (0 by default) and the placeholder (';' by default) to put into the selector and host fields unused in the i type (and the port field is always set to 0). It also pads every input line with the amount of spaces required to make the line length the same as the longest one in the input. All this is done to make your output Gophermap look nice when viewed in plaintext as well.
Note that the tool does not output the trailing dot to end the Gophermap, because its output can be used as a part of another Gophermap. To end the map manually according to the RFC1436, just invoke printf '.\r\n' afterwards redirecting to the same output.
Example of using gopherinfo.sh in combination with FIGlet, using 4 leading spaces, 0 trailing spaces and | as the placeholder (CR and Tab characters in the output are not shown):
$ figlet 'Bash it' | bash gopherinfo.sh 4 0 '|'
i ____ _ _ _ | | 0
i | __ ) __ _ ___| |__ (_) |_ | | 0
i | _ \ / _` / __| '_ \ | | __| | | 0
i | |_) | (_| \__ \ | | | | | |_ | | 0
i |____/ \__,_|___/_| |_| |_|\__| | | 0
i | | 0
A non-trivial task would be using this output in some Web-based services like Happy Net Box. You have to paste it in a format that the browser's text input element wouldn't mess with. To do this, you need the following steps:
- Pipe the
gopherinfo.shoutput into the autoquoter like this:| ( read -rsd '' x; printf '%q\n' "$x" ) - Copy everything except the first dollar sign of the output to your clipboard.
- In your Web browser, open a developer console (F12), type
console.log()and put the cursor between the brackets. - Paste your escaped string and hit Enter. If everything went correctly, the output should not be mangled.
- Copy your
console.logoutput again (make sure to fully copy the last line too!) and paste it in your Web service's posting textarea.
This hack also appies to any Gophermaps and not just the fragments generated with this tool.
Or, if you happen to have a working clipboard, you can just pipe the tools' output to | xsel -bi (on Linux) or | pbcopy (on Mac) and try pasting it directly. In all probability, it might work, but no one can guarantee.
phlow.sh
This tool processes every line of text from the standard input to fit exactly the given amount of characters, optionally adding some leading and/or trailing whitespaces after the reflow is done. It also replaces all LF line endings with CRLF in the output to achieve maximum compatibility with legacy clients.
As phlow.sh does not know anything about hyphenation rules and doesn't do any heuristics, it just breaks at whatever whitespace is the closest to the page's right edge.
Example - fitting the previous paragraph into 30-character width and prepending every line with 5 spaces (CR characters in the output are not shown):
$ echo 'This tool processes every line of text from the standard input to fit exactly the given amount of characters, optionally adding some leading and/or trailing whitespaces **after** the reflow is done. It also replaces all LF line endings with CRLF in the output to achieve maximum compatibility with legacy clients.' | bash phlow.sh 30 5
This tool processes every
line of text from the
standard input to fit
exactly the given amount of
characters, optionally
adding some leading and/or
trailing whitespaces
**after** the reflow is
done. It also replaces all
LF line endings with CRLF in
the output to achieve
maximum compatibility with
legacy clients.
gmi2map.sh
This tool converts Gemtext documents into browsable Gophermaps. It basically combines the functionality of both previous tools and adds link processing and triple-backtick removal (because in Gopherspace, all text is supposed to be preformatted) on top of them. Unlike gopherinfo.sh though, it doesn't care about the maximum length of the source (if you need to, the reflow logic is there), but it is expecting the entire document from the standard input, and as such, does add the trailing dot at the end of the generated Gophermap. That's why, for the beginners, this sole script might actually be everything you need to get you started with Gopher publishing.
Note that by default, reflow logic in gmi2map.sh is optional and you have to specify the page width yourself if you need it. Actually, full usage syntax looks like this:
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.
Example - imagine we have this rudimentary Gemtext document in the example.gmi file:
I write short Gemtext here.
I write a bit longer Gemtext here to showcase reflow capabilities of Bopher Tools' gmi2map.sh script, because it really is cool.
=> gopher://happynetbox.com:79/1luxferre Anyway, why not publish it on Gopher?
=> https://chronovir.us Or read my blog on Web...
See ya!
When running cat example.gmi | bash gmi2map.sh 67, 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
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
.
Note that this tool hasn't been tested for all possible edge cases yet, so I recommend to always verify the generated maps yourself. But it definitely makes their creation a lot easier than doing it by hand.
gmi2txt.sh
This tool converts Gemtexts into CRLF-terminated and preformatted plaintext files ready to be served on Gopher. It has the same parameters as gmi2map.sh sans the placeholder character. Link lines are converted to the [description]: [url] format and, unlike gmi2map.sh, also are subject to reflows like everything else.
Example - imagine we have this rudimentary Gemtext document in the example.gmi file:
I write short Gemtext here.
I write a bit longer Gemtext here to showcase reflow capabilities of Bopher Tools' gmi2txt.sh script, because it really is cool.
=> gopher://happynetbox.com:79/1luxferre Visit my Gopher homepage
=> https://chronovir.us Or read my blog on Web
See ya!
When running cat example.gmi | bash gmi2txt.sh 67 5, this file translates to the following plaintext:
I write short Gemtext here.
I write a bit longer Gemtext here to showcase reflow capabilities
of Bopher Tools' gmi2txt.sh script, because it really is cool.
Visit my Gopher homepage: gopher://happynetbox.com:79/1luxferre
Or read my blog on Web: https://chronovir.us
See ya!