Dot Bashprompt Public Release

A few weeks ago I got an email from Srikanth Agaram who wanted to know if it was okay to use and modify a prompt I'd posted online a while back. Of course - that's what it's there for. I said I'd be interested in seeing what he's doing with it if he made extensive modifications. He had, and they were very interesting ( ). So interesting that it took me several days to process what he was doing, and it significantly helped me get started on an idea I'd had in mind for years but hadn't been entirely sure how to implement: modularizing Bash Prompts to make them easier to assemble. I'm not following quite the same methodology he does (I fully separate colourization from information generation, he does not), but it was his separation of the prompt into multiple small functions that got me started.

So: this is to announce the public release of Dot Bashprompt. Installation is marvellously easy:

$ git clone ~/.bashprompt
$ source ~/.bashprompt/promnow
$ promnow

The last command will give you instructions on its use, including how to change your prompt to one of the ones bundled with it. If you like it, you can add a couple lines at the end of your ~/.bashrc:

# ~/.bashrc
source ~/.bashprompt/promnow
promnow <prompt-name> # replace "<prompt-name>" with the name of a prompt you like

That's it.

That's the theory, anyway. If you think you know something about a computer subject, just try releasing software related to it. I think I know something about Bash Prompts, I wrote "The Bash Prompt HOWTO" in 1998 (and updated it several times over the years). I've written a lot of Bash code. But I was soon to learn how little I knew.

I managed to get two co-workers and a friend to install the package. The installation is in fact as easy as I portray it above, and that's great. But three people, multiple problems:

I feel obliged to warn you at this point that you should only continue to read this post if you are A) deeply (and I mean DEEPLY) intrigued by the minutiae of Bash, or B) an insomniac in desperate need of a soporific.

Person Number One:

I had initially put my private github address rather than the public one in the "git clone" command. Easily fixed.

She uses the Mac's default terminal with a white background and black text. All my prompts are designed using a black background, and they look like crap on a white background. Not so easily fixed (although it can be done).

Person Number Two:
One of the prompts immediately exploded. This turned out to be because I'd left an obsolete function name in the prompt. Easily fixed: update the function name to point to the one that replaced it.
Person Number Three:

The first prompt he tried exploded. Happily, he was a good friend and one Google chat later I'd figured out the problem. I use ls -l to get the sizes of files in the current directory and, once collected, add them together. His default setting for ls is alias ls=ls -lh, which isn't necessarily a bad idea (I disagree with re-aliasing utility names, but I'll skip the long digression as to why), but with that alias in place, the file sizes all had "K" or "M" appended to them, so attempting to add them together caused Bash to barf.

This is hard to fix. Not in the specific case, but the general case. What if someone aliased other Unix utilities I use in the prompts like awk or sed or (most likely) grep? That could get really ugly. I can run unalias -a at the beginning of each function, but to be safe it has to be in every one. And what if instead the user did something like function ls () { /bin/ls -lh "$@" ; }? Functions are a better option than aliases in Bash (more flexible, less weird behaviour), and if people overwrite common utility names with functions, the functions inside Dot Bashprompt are built on quicksand. <sigh>

Person Number Four (aka "me"):

In Linux, you can act as if there are 16 colours available for making prompts. They only have numbers, but they come in eight sets of two that are effectively black and dark gray, dark and light cyan, dark and light green, brown and yellow, dark and light red, dark and light blue, pink and purple, light gray and white. In each pair, the lighter colour is the "bolded" version (that's how the documentation refers to it) of the darker colour. The colour distinction seems to depend both on the terminal you're using and the font being used, but on Linux, it works. The Mac takes the "bold" part of this much more literally: the colour distinction is totally gone. This is most obvious with dark gray, because it's essentially "bold black." Whoops, can't see that on a black background ... That breaks several prompts, and to fix it I'd have to cripple the Linux version of the prompt. Or use OS detection to rewrite colour settings, but that seems to violate the Principle of Least Surprise ...

I found more problems, but even I'm getting tired of listing them out.

Despite all of which (or perhaps because of it) I'm enthusiastic to continue developing this. We'll see how it goes.