84 lines
4.4 KiB
Markdown
84 lines
4.4 KiB
Markdown
# Bopher-NG: A better Gopher browser in pure Bash
|
|||
|
|
|
||
|
|
> “Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.”
|
||
|
|
> _― Antoine de Saint-Exupéry, Airman's Odyssey_
|
||
|
|
|
||
|
|
## What is it?
|
||
|
|
|
||
|
|
Bopher-NG is an ambitious attempt to write a full-featured Gopher client/browser in under 300 SLOC of pure Bash code. It started off as a really crude and unoptimized prototype developed right in [this blog post](https://chronovir.us/2023/03/28/I-wrote-a-browser/) for educational purposes.
|
||
|
|
|
||
|
|
Improvements over the original Bopher from that post:
|
||
|
|
|
||
|
|
- mouse support (where possible)
|
||
|
|
- smoother rendering and scrolling
|
||
|
|
- better edge-case stability
|
||
|
|
- multi-level navigation history (although you can only go back)
|
||
|
|
- status bar with currently opened resource name
|
||
|
|
- ability to accept `gopher://` URLs from the command line
|
||
|
|
- ability to save the URL to the currently viewed resource into the stash text file
|
||
|
|
- ability to force-download pages instead of viewing regardless of their type
|
||
|
|
|
||
|
|
"Pure Bash" means any external commands must only be used if absolutely required. For now, Bopher-NG only depends on three external commands (all POSIX-compliant):
|
||
|
|
|
||
|
|
- `cat` (to handle possibly binary data read from the socket)
|
||
|
|
- `stty` (to fetch current terminal size in rows and columns)
|
||
|
|
- `date` (to shape entry timestamps when stashing links)
|
||
|
|
|
||
|
|
## Which Bash versions are supported?
|
||
|
|
|
||
|
|
Bopher-NG was only tested on Bash 5.1, but should support any version from 4.2 and up.
|
||
|
|
|
||
|
|
## How to start Bopher-NG?
|
||
|
|
|
||
|
|
Just run it specifying all the necessary components of the Gopher resource:
|
||
|
|
|
||
|
|
```
|
||
|
|
bopher-ng.sh host[ port][ selector][ type]
|
||
|
|
```
|
||
|
|
|
||
|
|
Or, you can just specify a valid `gopher://` URL:
|
||
|
|
|
||
|
|
```
|
||
|
|
bopher-ng.sh gopher://host[:port]/[type][selector]
|
||
|
|
```
|
||
|
|
|
||
|
|
E.g. running `bopher-ng.sh gopher://texto-plano.xyz:70/0comandos.txt` is the same as `bopher-ng.sh texto-plano.xyz 70 comandos.txt 0` and will open the same document.
|
||
|
|
|
||
|
|
In both cases, only the host is required. If everything else is omitted, the port will default to 70, the selector will default to `/` and the resource type will default to 1.
|
||
|
|
|
||
|
|
## How to control Bopher-NG?
|
||
|
|
|
||
|
|
- Scrolling: Up/Down arrow keys, k/j keys or mouse scroll wheel (if supported)
|
||
|
|
- Page scrolling: PgUp/PgDn keys or h/l keys
|
||
|
|
- Link navigation (keyboard): s - focus on the next link, w - focus on the previous link, Enter/Space - visit the focused link (or download if it points to a binary file), d - force-download the contents of the link
|
||
|
|
- Link navigation (mouse, if supported): left click on the link - focus and visit (or download if it points to a binary file), middle click - focus and force-download the contents
|
||
|
|
- Go back: b or right mouse click anywhere (if supported)
|
||
|
|
- Stash the link to the currently open resource: S (shift+s)
|
||
|
|
- Quit the browser: q
|
||
|
|
|
||
|
|
## What is the link stash?
|
||
|
|
|
||
|
|
Link stash is a viable and interoperable alternative to both bookmarks and clipboard that can be implemented with pure Bash. Essentially, it's an append-only text file at a fixed location (`~/.bopher-links.txt` by default) where the user can instruct Bopher-NG to save the link to the currently viewed resource. For your convenience, links are stashed with a UTC-based timestamp and in the `gopher://` format, so they can be copied from the file later and used in other browsers.
|
||
|
|
|
||
|
|
You can override the `BOPHER_LINKSTASH` environment variable to change the location and name of this file if you need to.
|
||
|
|
|
||
|
|
## Where do the downloads go?
|
||
|
|
|
||
|
|
By default, they go to your current working directory, i.e. the directory you are running this script from. To override this with a fixed path, set the `BOPHER_DLDIR` environment variable.
|
||
|
|
|
||
|
|
## Which platforms is the mouse supported on?
|
||
|
|
|
||
|
|
Bopher-NG's mouse input is supported on any terminals that support the 1000 **and** 1006 mouse reporting modes. This includes but is not limited to:
|
||
|
|
|
||
|
|
- Linux GUI terminal emulators (xterm, Konsole, urxvt, any VTE-based terminal emulator);
|
||
|
|
- Linux bare terminals via GPM + [LCXterm](https://gitlab.com/AutumnMeowMeow/lcxterm) (sorry, I don't know why no one implemented it in GPM itself in 23 years);
|
||
|
|
- macOS Terminal;
|
||
|
|
- OpenGL-based xterm-compatible terminal emulators like WezTerm, Kitty, Alacritty etc.
|
||
|
|
|
||
|
|
Note that this support is required at the client side only. For instance, you can safely run `bopher-ng.sh` on any compatible Bash version in an SSH session on your terminal and still be able to use mouse there.
|
||
|
|
|
||
|
|
|
||
|
|
## What is the license on this?
|
||
|
|
|
||
|
|
Fully public domain
|