Bopher Tools is a small collection of simple shell scripts that are:
- written in pure Bash with no external dependencies;
- 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):
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:
1. Pipe the `gopherinfo.sh` output into the autoquoter like this: `| ( read -rsd '' x; printf '%q\n' "$x" )`
2. Copy everything except the first dollar sign of the output to your clipboard.
3. In your Web browser, open a developer console (F12), type `console.log()` and put the cursor between the brackets.
4. Paste your escaped string and hit Enter. If everything went correctly, the output should not be mangled.
5. Copy your `console.log` output again (make sure to fully copy the last line too!) and paste it in your Web service's posting textarea.
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.
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.
$ 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 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:
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.