permacomputing

Source repository for the main permacomputing wiki site
git clone http://git.permacomputing.net/repos/permacomputing.git # read-only access
Log | Files | Refs

commit f1464747615565d33e989b269282bfcd45ef86ae
parent ee0d42a4860aec53c999fcd18c1ec1262b107f34
Author: spacehobo <spacehobo@web>
Date:   Sun, 17 May 2026 18:28:08 +0200

Better explanatory text

Diffstat:
Mspacehobo.mdwn | 26+++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/spacehobo.mdwn b/spacehobo.mdwn @@ -1,18 +1,28 @@ # Just a Rum-Soaked Space Hobo with an Inordinate Fondness for Makefiles +Hello, I'm from the [London Permacomputing Group](https://london.permacomputing.net). I've been using Unix and The Internet since the 1980s, and Linux since the mid-90s. I like small open software I can wrap my head around, but I'm not a fan of those "suckless" folks. + ## Prompt Engineering -Hey, check out my neat `bash` prompt, which I put in eik's `/etc/bash_completion.d/prompt.sh` so everyone gets it: +Check out my neat `bash` prompt, which I put in eik's `/etc/bash_completion.d/prompt.sh` so everyone gets it: * [Prompt Engineering](https://git.permacomputing.net/prompt-engineering/files.html) -The prompt environment is fairly limited. It can do parameter expansion, reference expansion, arithmetic expansion, and a couple other neat tricks. You can shell out, but if you do that overwrites the variable that contains the exit code of the last program you ran (`$?`). Tools such as the `__git_ps1` hacks do their best to only use features of bash that work internally to bash itself. + + +The `$PS1` text expansion environment is fairly limited. It can do parameter expansion, reference expansion, arithmetic expansion, and a couple other neat tricks. You can shell out, but if you do that it can overwrite the variable that contains the last exit code (`$?`). A lot of heavyweight systems like powerline or starship will tuck this data away before running loads of programs every time you hit return at the shell. I wanted to see if I could do more with less. + +Tools such as the `$(__git_ps1)` hacks do their best to only use features of bash that work internally to bash itself. They make internal functions that try not to fork off processes if they can help it. I was inspired by the Debian `$PS1`'s handling of their `$debian_chroot` variable, and decided to try and make a dynamic prompt that only shows information if it's relevant. + +### Implementation Details This prompt uses the `_noop` array (with only `${_noop[0]}` defined) to turn arithmetic expressions into defined/undefined responses. This lets us use some of the brace-expansion features to specify alternate output, so we can display the error code or number of jobs in the background *only* if they're non-zero, and we can style them with a high degree of freedom. It also only displays the hostname if the `$XDG_SESSION_TYPE` is `"tty"` or if we have variables set by `ssh`, `sudo`, or `doas`. It dynamically displays the `$SUDO_USER` and `$DOAS_USER`, if either is defined. -What this means is that on your local desktop system, when you log in, your prompt is merely: +### Behaviour + +What this means is that when you log in on your local desktop system, your prompt is merely: ~$ @@ -20,11 +30,13 @@ But the same prompt on a remote system will show the more common: user@hostname:~$ -And if you are sudo'd in a chroot with background processes looking at a git repo after a command that exited with an error code of `1`: +And if you are sudo'd in a chroot with two background processes while looking at a git repo after a command that exited with an error code of `1`: + + (1)[2](thechroot)root<user>@hostname:/home/user/src/therepo{main $%}# - (1)[2](thechroot)root<user>@hostname:~/src/therepo{main $%}# +Each of these dynamic pieces of information will be bold and colour-coded, if `tput setaf 1` was successful on your terminal or if your `$TERM` seems likely to support it. Otherwise you get a plain text version. -with coloured styling information on all the various parts, if `tput setaf 1` was successful on your terminal or your `$TERM` seems likely to support it. Otherwise you get a plain text version. Here's the plain text version so you can see how it works: +#### Here's the plain text version so you can see how it works: ```sh unset _tty @@ -41,4 +53,4 @@ _noop[0]='array accesses turn 0/nonzero into defined/undef!' PS1+='\$ ' ``` -I just think it's neat! +# I just think it's neat!