Subscribe to PHP Freaks RSS

Avoid Costly Mistakes and Confusion - Colored Prompt Tip

by Timothy McKeown on Mar 6, 2009 10:22:23 AM - 5,952 views

I thought I'd share a little trick for my fellow Linux users. Some of you may already know this but it's very helpful for me when SSH'ing from development to live servers, so I don't make any mistakes. This trick will allow you to change the color of your prompts for each individual server.
For this trick to work, you simply edit your bashrc file on whatever server you want to change the color of your prompt. Some general steps if you're not familiar:

1) Use your favorite editor to edit your bashrc file:

vim ~/.bashrc

2) Comment out the default setting for PS1:

#PS1='[\u@\h \W]\$ '

3) Add (this is my setting for a user, it's pink ;) ):

export PS1="\[\e[0;35m\]${PS1}\[\e[m\]"

for Root settings:

PS1='\[\e[0;31m\]\u \[\e[1;34m\]\w \[\e[0;31m\]\$ \[\e[0;32m\] '

Here's a list of different colors:

Dark Gray-1;30
Light Blue-1;34
Light Green-1;32
Light Cyan-1;36
Light Red-1;31
Light Purple-1;35
Light Gray0;37    

4) Keep repeating these steps on your desired servers with your preference of color.

5) For the colors to take effect you have to either restart your console or source your bashrc file:

source ~/.bashrc

or if your last command was to edit the bashrc file you can use bang-dollar (which saves me a lot of time if I'm dealing with the same file a lot):

source !$

I know this helps me out a lot, so I hope this helps others to avoid mistakes and improves the efficiency of your work!


No comments have been posted.

Add Comment

Login or register to post a comment.