More Useful and Interesting Bash Prompts

A while back, we listed 8 Useful and Interesting Bash Prompts. That turned out to be one of our most popular articles, and still generates user response and feedback. This time we’ve found a few more gems, as well as some handy tips and tricks for having the coolest shell prompt on the proverbial block.

Using These Prompts

Some of the following prompts are one-liners, and can be pasted directly into your terminal for (temporary) use. To make them permanent, you’ll have to paste the code into your .bashrc or .bash_profile.

The larger, more complex prompts such as Twtty should be saved to their own script file (such as myprompt.sh), and you place a line like

in your .basrc file to “import” them.

Twtty Prompt

This is a two-line prompt that holds quite a bit of information including username, hostname, working directory, time, and command history number. Because of the technical and visual complexity, it’s best to place this prompt script in its own file, then source it from your .bashrc or .bash_profile as described above.

morebashprompts-twtty

One important thing to note about this prompt is that the horizontal bar scales to fit the width of your terminal, and that the working directory line will truncate itself when it gets too large.

If you have any problems with the above code snippet, the plain text version can be downloaded here.

High-Performance Minimalist Prompt

All the complexities of a fancy prompt like Twtty do take up extra CPU cycles, and while it’s certainly not going to grind your system to a halt, it can add up. If you want something that packs a lot of info without slowing you down, I suggest this:

morebashprompts-minimal

One interesting thing to note here is the use of the variable $? at the end. This signifies the exit status of the last command entered. 0 means all is well, any other number usually indicates an error.

Rob’s Prompt

This is one of the more popular prompts floating around the Internet. The code is small and simple, yet it gives many of the features found in the larger, more complex examples.

morebashprompts-robs

MegaFancyPrompt

The name is entirely deserved – this prompt is quite large and extremely fancy. It’s got color, titlebar control, user-awareness, proxy detection, screen detection, job count, and more. In short, just about every feature found in the other prompts we’ve mentioned can be found here, and quite a few others. If you want it ALL in your prompt, this is it.

morebashprompts-megafancy

Note: Not all features are visible at all times, so while it may not look like much in the screenshot, you can check out the full (documented, commented) script file here for details on how to get the visible parts you want.

Bonus – Finding the Right Colors

As you may have noticed, most of these prompts use color, and the color is often represented in a coded form like ‘\033[1;30m’, which is quite difficult to read or remember. An easy way to see all your available colors, and preview what they’ll look like, is to simply paste the following snippet into your browser:

Which will output each color code with its number.

morebashprompts-colortest

Conclusion

There are, of course infinite variations that could be packed into your prompt. Nearly any kind of textual data can be added in, and bash’s developers have had decades to add in functionality. Some readers have even commented about running custom Python or Ruby scripts from within the prompt. Whatever you do, make it functional, and if it’s REALLY cool, drop us a link in the comments!