Monday, March 2, 2009 Terminal Screenshot Colour Scheme

I recently received this email from inquisitive reader Dermot:

I was going through your website tonight and find it really easy to follow how the commands and descriptions are laid out. I have a question about the screenshots you use.

The terminal screenshots have a black background, with "[me@llinuxbox me}$" in green and the commands to be run in white. How did you get this colour scheme? Ive been asking on Ubuntuforums and other forums, as it would really make the lines on which you enter commands stand out against the output results of those commands.

Please get back to me if you get a chance.



Thanks Dermot for taking the time to write. The "screen shots" you refer to aren't actually screen shots at all. They're implemented in hand-coded HTML and CSS, but you can create the same effect on your own system. Here's how:

The contents of your prompt are defined in an shell variable called PS1. You can examine its contents like this:

me@linuxbox ~$ echo $PS1

This example is from an Ubuntu system. Other distributions will be different.

To set the colors, first use the Edit -> Current Profile dialog in gnome-terminal to set the color scheme to "White on black":

Next, you need to add some ANSI color codes to the prompt string contained in PS1. To change the prompt to green and then back to its original colors (so that subsequent text will remain white), you need to change the prompt string to this:


You can test your prompt by setting the PS1 variable this way:

me@linuxbox ~$ PS1="\033[0;32m${debian_chroot:+($debian_chroot)}\u@\h:\w\$\[\033[0m\] "

After you are satisfied with the new prompt design, you can make it permanent by adding these two lines to your .bashrc file:

PS1="\033[0;32m${debian_chroot:+($debian_chroot)}\u@\h:\w\$\[\033[0m\] "
export PS1

Hope this helps!

You can read more about configuring the prompt at the Linux Documentation Project. They have an excellent HOWTO document entitled:

The Bash-Prompt HOWTO

No comments:

Post a Comment