Changing the color of characters in the prompt (or shell), make them more readable. If you are using colors group, you can sense by color, this will eliminate the risk of having a lengthy command prompt.
Information that can be transmitted by the colors
You can assign the green commands for a first machine (host) and blue for another, or green when the system is not loaded, yellow when resources are used or you choose a color for root prompt, another for an MC ...
Two methods are available are possible. The most used (but the less effective) is to insert escape characters. The following shows the chain commands in blue:
This method has two major drawbacks: its syntax is unreadable, so prone to entry errors, and it is only applicable if the terminal window supports ANSI escape sequence,
- changing color of the prompt(or shell) using tput, your definitions are portable to other terminal emulators.
$ BLUE=$ (tput setaf 4)
$ BLACK=$ (tput setaf 0)
$ PS1=" [$BLUE] u@h] [$BLACK] "
- Understanding these lines
- tput is firstly used to define a variable that contains the sequence of characters to force the color to blue.
- The second line did the same for black.It is now necessary to know the escape sequences, since tput manages a correspondence file descriptions to all terminals file to consult to find the appropriate sequence terminal physical or emulated.
- The third line, finally, uses both variable and $ $ BLUE BLACK in the definition of the $ PS1 prompt
- Note: You can view a complete list of commands man tput and man terminfo.
Published by netty5
Latest update on January 31, 2010 at 05:25 AM by jak58.