Tuesday, December 7, 2010

BASH customizing: Spice up the way your bash looks

Display multiple colors in bash shell prompt

Add this line to your .bashrc file
# Prompt text background by orange: two lines, title is full path of pwd,
PS1='\e[42m\d \@ \! \# \[\033]0;\h:\w\007\]\u@\h:\w\e[0;0m\nbash$ '

For changing prompt line color, use values from 40 to 47 instead of 42 in "\e[42m" 

\d - the date
\@ - the current time
\! - The history number of the command
\# - the command number of this command
\u@\h -Username@hostname (Useful when you use SCP to copy files between workstations)
\w – Current working directory (Full path)
\e[0;0m - Color ends here so that your shell color is not changed after this
\n - End of line; For prompt to be in the next line so that you have more space to type
bash$ - Just a prompt word and space for you to type

 Change the prompt color using tput

You can also change color of the PS1 prompt using tput as shown below:
$ export PS1="\[$(tput bold)$(tput setb 4)$(tput setaf 7)\]\u@\h:\w $ \[$(tput sgr0)\]"


No comments:

Post a Comment