Random Stuff from a software developer

Here is a little tip so that you can quickly tell which linux machine that you are currently logged into. The easy way to do this is to colour code the shell prompt.

In bash the PS1 enviroment variable controls how the prompt is formatted. On a debian squeeze install it would be set to something like this by default

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

That of course does look somewhat confusing mostly because of the escaping. The letters with a '\' at the front are telling bash to also display certain things but I will cover that in another post. Lets add some colour.

To add some colour we need to add a control sequence to the shell prompt this tells the terminal to enable a specific colour then at the end of the prompt turn that colour back to the default for the terminal.

to set the colour we need to apply this to the beginning of the enviroment variable (this is using the color red 31m)

\[\033[31m\]

Then we also need to append the close sequence to the end of the enviroment variable.

This is a quick tip if you use an xserver that is running remotly and you want to set the DISPLAY enviroment variable when you login to the machine using ssh. It is actually very simple to do.

When you use ssh it will automatically set the SSH_CLIENT enviroment variable to contain the client connection details eg the ip address port number etc.. to get this to work you will need to paste the following into your .bashrc file.