~tomterl/thp

tom's hare prompt - server and client
moon,sun: constants moved from chrono to date
Compile against latest hare main branch.
readme: response 'config reloaded'

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~tomterl/thp
read/write
git@git.sr.ht:~tomterl/thp

You can also use your local clone with git send-email.

Tom’s hare prompt client and server

A small and slightly silly implementation of a prompt server and client for bash and zsh.

This is my playground project to get acquainted with the programming language hare and its standard library, touching network communication, FFI bindings to a c library, using static memory to build dynamic strings, etc. I just thought I could as well make something usable.

See the manpages for further information, limitations, caveats.

To use this as it is, you need to use a nerdfont in your terminal(s), not everything used from there per defaults is configurable (yet).

Why a client server solution?

Prompt solutions like starship go to great length to manipulate environment variables to maintain state. If the shell provides a unique id when requesting the next prompt, a server can store the state and associate it via that id. Both programs are comparativly small, e.g. thpd has 800k stripped when linked against libgit2, whereas starship is 7.8M big on my system.

Building

You need hare, follow the instructions at harelang.org to install it.

To build thp with all modules included, you need liblua, lua-dev, libgit2 and your platforms libgit2-dev equivalent installed, then issued

make EXTRA_MODS="project git clock timer shind uptime moon sun star lua"
make EXTRA_MODS="project git clock timer shind uptime moon sun star lua" test
make PREFIX="${HOME}" install

To build with just the modules you use in your spec, use MODS:

make MODS="path host project timer uptime moon sun star lua"
make MODS="path host project timer uptime moon sun star lua" test
make PREFIX="${HOME}" install

These instructions assume that you have ~/bin in your PATH and ~/man in your MANPATH.

The protocol

Client

The protocol is quite simple and spur-of-the-momenty. After the connection is established, the client sends three lines

infoline: PWD!COLS!ID
control line: REMOTE_SESSION:LAST_CMD_STATUS_OK:RELOAD_CONF:SET_TIMER_MARK:IS_ROOT:SET_TITLE:SHELL_MARKER
prompt line: PROMPT_SPEC

A real world example looks like this

/home/tom/Projekte/thp!117!259201668342679
ftffftz
s:git|f:|m:clock|l:|s:def|m:path|s:;;reset|m:sigil

server

The server responds with

  • the prompt string in one line, newlines send as \n
  • ’config reloaded’ when the third byte in the control line is t and the configuration was reloaded. (thp -r)
  • ’mark set’ when the fourth byte in the control line is t and the server was compiled with +timer (thp -i $ID -t)
  • ’mark error’ when the fourth byte in the control line is t and the server was compiled without +timer

Contributing

thp is part of my dotfiles project. Report bugs and ideas by opening tickets or writing to the public-inbox mailing list. You can drop in a possibly very asynchronous conversation on IRC (it is recommended to use a bouncer to not miss replies).

If you write code, try to write tests (if possible). Contributions should be valgrind clean, if you cannot get to that state, attach the valgrind information, or better a link to a paste site like paste.sh.ht holding the valgrind output. thpd is potentially a very long running process, it should not leak memory.

Do not follow this link