Changing the color of the command prompt(shell)

Last update on December 1, 2008 09:37 AM by netty5
Published by netty5

Changing the color of the command prompt(shell)





Purpose


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 ...

Methods


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:

$ PS1="\[\033[0;34m\][\u@\h]\[\033[0m\]"


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,

Using tput

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
variable.

Note: You can view a complete list of commands man tput and man terminfo.
Best answers for « Changing the color of the command prompt(shell) » in :
Command Prompt full screen with the pointer ShowCommand Prompt full screen with the pointer If you need a command prompt in full screen, here's how: Open the command prompt, and maximize the window (it is still not full screen). Right click on the top of the window Edit/ Properties...
How to resize a disk partition ShowHow to resize a disk partition For Windows Vista users Solution 1: Using Disk Management Solution 2: Using Command Prompt Software Download There are some simple ways to manage your disk partitions to either expand or reduce them....
Prevent the automatic closing of the command prompt ShowPrevent the automatic closing of the command prompt Sometimes, often see the command prompt window closes when you want to see information such as your IP ... To address this problem, just launch the command prompt using cmd /K...
Cmd - cmd.exe Showcmd - cmd.exe cmd.exe (cmd signifiant Windows Command Prompt) is a Windows NT/2000/XP generic process which opens a text-mode console for running programs using a command line. The process cmd is not in any way a virus, a worm, a Trojan horse,...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...
UNIX system - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence its name "shell". The shell therefore acts as an intermediary between the operating system and the user using command lines...