CUSTOMISE YOUR COMMAND LINE PROMPT



To customise your Bash command line prompt, you need to modify the .bashrc fi le in your home (~) directory. Chances are that file
already exists (and perhaps there are even prompt-related lines in there already), but any changes you add on the end of the file using a text editor will take precedence, so that’s fine.

We’re going to start by defi ning some colours in the fi le so you can use them in your prompt.

Bash colour codes are as follows:

Black - 0;30
Blue - 0;34
Green - 0;32
Cyan - 0;36
Red - 0;31
Dark Gray - 1;30
Light Blue - 1;34
Light Green - 1;32
Light Cyan - 1;36
Light Red - 1;31
Purple - 0;35
Light Purple - 1;35
Brown - 0;33
Yellow - 1;33
Light Gray - 0;37
White - 1;37

They can be added to the .bashrc file with lines in the following format, in a function:

RED=”\[\033[0;31m\]”
GREEN=”\[\033[0;32m\]”
BLUE=”\[\033[0;34m\]”
PURPLE=”\[\033[0;35m\]”
GRAY=”\[\033[0;37m\]”

Next, after defi ning the colours you wish to use, you need to defi ne the prompt itself with a line such as:

export PS1=”${RED}\u${GREEN}@${BLUE}\h ${PURPLE}\w${GRAY}$”

In this line we are setting the prompt to our username ( \u ) to be red, including the ‘@’ character in green, the machine’s hostname ( \h ) in blue, current path ( \w ) in purple and the final prompt ( $ ) in grey.

The Bash online documentation (do a Google search for ‘bash prompt escape sequences’) details a host of other items you can include, so experiment! However, try not to get too carried away... you might fi nd that having a prompt that takes up half the screen becomes tiring very quickly!

Comments

Popular posts from this blog

Byobu : Japanese term for decorative