Posted on Sun 02 April 2017

a 2 line bash prompt

Back in the DOS era of personal computing, the default prompt was the letter name of the current drive, followed by a colon and a >. So A:> or C:> if you were wealthy enough to afford a hard disk. DOS really had only one shell for a great many years: COMMAND.COM.

When it became possible to customize your shell prompt, people started putting their current path in the prompt. And starting in the time of EGA it became possible to use a denser text mode than 80x25: 80x43. VGA brought 80x50, 80x60, and weird tiny-text modes like 132x43 and 132x50. Typical people spent $400 on a 13 or 14 inch 4:3 monitor. Enthusiasts spent $1000 on a 16 or 17 inch monitor, and so they could usually make out the differenc between an O and a 0.

The default bash prompt is an obvious holdover from such times. Remember, if you fire up a terminal under X11, it will default to 80x25.


or if your distribution did the most obvious customization:


which is actually pretty good. It supplies all the necessary information, and does so in a way which is useful to cut and paste into commands like rsync, scp or whatever.

It could be made more convenient, though, if you put it on two lines instead of one. Right now, cutting and pasting means carefully lining up the whole thing and avoiding copying a command you may have started to type, and certainly carefully omitting the $ or # separator.

So set PS1 to \u@\h:\w\n$ to obtain that convenience. The whole first line is your user, host and path, and your commands start on the second line.

If you want to spiff it up with color, I recommend a reverse color combination for the path: white on blue, for example, is nicely readable whether you prefer a generally black terminal or a generally white terminal. Filling out the rest of the line with the same or a complementary background color can help you spot your last command in a long scrollback.

For more ideas, consult the bash prompt HOWTO

Comment on June 24 from Kartik Agaram:

One extra trick I use is to drop the ‘$’ from the second line so I can start commands from column 0. That way I can copy commands more easily (without needing special characters in the prompt) and get clean indentation for multi-line commands. Which encourages me to write more multi-line commands.

© -dsr-. Send feedback or comments via email — by continuing to use this site you agree to certain terms and conditions.

Built using Pelican. Derived from the svbhack theme by Giulio Fidente on github.