Gemini CLI protocol client written in 100 lines of ANSI C.
Other similar Gemini client projects written in few lines of code
successfully shows how simple Gemini protocol is. This code is far
from straight forward. But I had a different goal in mind.
I tried to pack as much as possible in 100 lines of ANSI C. Initially
I struggled to fit simple TLS connection in such small space but
eventually I ended up with CLI client capable of efficient navigation
between capsules of Gemini space
Build, run and usage
Run build
script or use any C compiler and link with OpenSSL.
$ ./build # Compile on Linux
$ ./gmi100 # Run with default "less -XI" pager
$ ./gmi100 more # Run using "more" pager
$ ./gmi100 cat # Run using "cat" as pager
gmi100> gemini.circumlunar.space
In gmi100>
prompt you can take few actions:
- Type Gemini URL to visit specific site.
- Type a number of link on current capsule, for example:
12
. - Type
q
to quit. - Type
r
to refresh current capsule. - Type
u
to go “up” in URL directory path. - Type
b
to go back in browsing history. - Type
c
to print current capsule URI. - Type
?
to search, geminispace.info/search is used by default. - Type shell command prefixed with
!
to run it on current capsule.
Each time you navigate to text
document the pager program will be
run with that file. By default less -XI
is used but you can provide
any other in first program argument. If your pager is interactive
like less the you have to exit from that pager in order to go back to
gmi100 prompt and navigate to other capsule.
When non text
file is visited, like an image or music then nothing
will be displayed but temporary file will be created. Then you can
use any shell command to do something with it. For example you can
visit capsule with video and open it with mpv
:
xdg-open
or open
command to open file with default program forgiven MIME type.
you decided that your defauly pager is
cat
but for some capsules youwant to use
less
. Or you want to edit given page in text editor.In summary, you can open currently loaded capsule as file in any
program as long as you don’t navigate to other URI.
Browsing history in gmi100 works differently than regular “stack” way
that is commonly used in browsers and other regular modern software.
It is inspired by how Emacs handles undo history. That means with the
single “back” button you can go back and forward in browsing history.
Also with that you will never loose any page you visited from history
file and I was able to write this implementation in only few lines.
After you run the program it will open or create history .gmi100 file.
Then every page you visits that is not a redirection to other page and
doesn’t ask you for input will be appended at the end of history file.
File is never cleaned up by program itself to make history persistent
between sessions but that means cleaning up browsing history is your
responsibility. But this also gives you an control over history file
content. You can for example append some links that you want to visit
in next session to have easier access to them just by running program
and pressing “b” which will navigate to last link from history file.
During browsing session typing “b” in program prompt for the first
time will result in navigation to last link in history file. Then if
you type “b” again it will open second to last link from history. But
it will also append that link at the end. You can input “b” multiple
times and it will always go back by one link in history and append it
at then end of history file at the same time. Only if you decide to
navigate to other page by typing URL or choosing link number you will
break that cycle. Then history “pointer” will go back to the very
bottom of the history file. Example: