Thursday, 6 October 2005

Enhancing the System Prompt - $PS1

If you spend a lot of time remotely logging into several machines, or just have many terminals open using the $PS1 variable can aid in keeping track of the whole mess. Even prevent you from making silly mistakes as root.
For instance if you put:
    PS1="[\[\033[1;31m\]\u\[\033[0m\]@\h \W]\\$ "
at the bottom of your /root/.bashrc file. Every time you are logged in as root, the terminal will look like this:
    [root@hostname root]#
Suppose you have seperate accounts like a developer account, a regular account and remote machines account, then you can use separate colors for each of your accounts like, for developer account (magenta), regular account (blue) and remote machines (green) so you know at a glance which is which without reading every line of output looking for that regular text that blends in.

The actual color code is "1;31" inside the PS1 variable. The 1 says make it bold, and the 31 says the color (red). Other colors are:
1;30 Black
1;32 Green
1;33 Yellow
1;34 Blue
1;35 Magenta
1;36 Cyan
1;37 White
This is just a subset of PS1 variable tricks for more information on enhancing the system prompt, read the article at www-106ibm.com.

No comments:

Post a Comment