If you are like me, you'll probably have found yourself with multiple command lines on a terminal, together with their respective output. Searching those lines in the screen can be difficult, specially if your prompt is long (and with that, I mean more than 4 characters or so). A solution is to make your prompt more visible. How? Putting it in boldface mode.

While this sounds obvious (and easy), one may not know it until seen somewhere. I knew it, but as I use(d) ksh, I couldn't do it "safely" (the prompt does weird things when non-visible characters are in it). Anyway, one of the very first hacks of the BSD Hacks book (which I mentioned yesterday) made me think about this. It's not a hack by itself, just part of an example.

So let's do it. The way to achieve this depends on the shell you use. tcsh and zsh users are lucky, as it's a matter of four more characters in their prompt. The special control code %B turns on boldface, while 0 turns it off. For example, in tcsh: set prompt="%B%m%0 "; and in zsh: PROMPT='%B%m%0 '.

For bash users, it's a bit more difficult, as you have to manage escape codes directly. The way to enable boldface is with the e[1m code, and to disable it, with e[0m (in fact, this resets all attributes previously set). But note that you can't add that directly to your PS1 variable as these codes won't be printed. Doing so means that bash can't calculate the prompt's length correctly and will expose weird behavior when reaching the end of screen. Therefore you have to surround codes with [ and ]. For example: PS1='[e[1m]h$ [e[0m]'.

Now I'll leave it up to your imagination. Specifying escape codes lets you do many things, like using colors or manage xterm's titlebar (IIRC), not just boldface. Note that tcsh and zsh also allow direct escape codes.

Go to posts index

Comments from the original Blogger-hosted post: