Files
bopher-ng/tools/README-tools.md
T

40 lines
3.1 KiB
Markdown
Raw Normal View History

# Bopher Tools: a set of simple Bash scripts to not just browse Gopher but also create for it
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 other Gophermaps. 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:
```
$ 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:
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.
This hack also appies to any Gophermaps and not just the ones generated with this tool.