Sunday, August 7, 2011

How to change the appearance of the Bash Prompt

First of all - backup your .bashrc file
cp .bashrc .bashrc-backup

now edit .bashrc with your editor:
gedit .bashrc

in the end of the file add:

PROMPT_HOSTNAME='SET_HERE'

PROMPT_COLOR='1;37m'
PROMPT_COLOR2='1;32m'

PS1='\e[${PROMPT_COLOR}[\e[${PROMPT_COLOR2}\u@${PROMPT_HOSTNAME}\e[${PROMPT_COLOR}] $ '

the first color is for the normal font and barckets, and the second one is for the user name and host
.
30: Black/Dark grey
31: Red 32: Green
33: Yellow
34: Blue
35: Magenta

36: Fuscia

37: White/light grey

38: "Default"

foreground color
in the exmaple "1;37m" you will have to change the 37 to another number.
The 1 before it can be set into zero, it is for light \ dark colors
rename the PROMPT_HOSTNAME to your hostname (or anything you want) and save the file.

You can try the options below and can select the nice colour combinations of your choice.

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\e[${PROMPT_COLOR2}\u@\h\[\033[00m\]:\[\033[1;37m\]\w\[\033[00m\]\$ '

PS1='\n\[\033[1;34m\]\342\226\210\342\226\210 \u @ \w\n\[\033[0;36m\]\342\226\210\342\226\210 \t $ \[\033[0;39m\]'

PS1="$C_BLUE[$C_RED\$?$C_BLUE][$C_RED\u@\h:\w$C_BLUE]\$ $C_RESET"

Try my choice..
if [ $(id -u) -eq 1 ];
then # you are root
PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '
else # normal

cal

PS1='\[\033[01;34m\]\u @ \w\[\033[0;36m\]\t $ \[\033[0;39m\]♡'

fi

You can see a calendar at the begining...The command cal run each time when the terminal opened and calendar will be displayed.You can replace cal by other command also..



No comments:

Post a Comment