Tuesday, August 13, 2013

USER SPECIFIC BASH PROMPT CONFIGURATION


The bash prompt can be customized in numberous ways depending on user specific customization or sytem wide configuration.

USER SPECIFIC CUSTOMIZATION :
For user specific configuration we edit ~/.bashrc and add customization below the line “# User specific aliases and functions”. 
For example the sample `/.bashrc for user named test is as follows:

# .bashrc


# Source global definitions

if [ -f /etc/bashrc ]; then

        . /etc/bashrc

fi


# User specific aliases and functions

PS1='\u@\H:\w\$ '




In the above example the prompt will have user_name@hostname.domain.tld:/working/directory$ sequence yielding following 
output:

test@cbitss:~$


Users can also implement colourful prompt using following syntax :
 
PS1='\[\033[02;32m\]\u@\H:\[\033[02;34m\]\w\$\[\033[00m\] '

Above Prompt Setter will give colorful prompt as :
test@cbitss:~$ 


Bash supports a range of colour as listed below:
Black             0;30     Dark Gray     1;30
Blue               0;34     Light Blue    1;34
Green             0;32     Light Green   1;32
Cyan              0;36     Light Cyan    1;36
Red                0;31     Light Red     1;31
Purple            0;35     Light Purple  1;35
Brown            0;33     Yellow        1;33
Light Gray      0;37     White         1;37

'h' is used instead of 'H' to display hostname only and not complete url.

System-wide Configuration

To implement prompt setting system-wide the changes are made in /etc/bashrc file as follows :
36 #[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "

 
Comment 36 line number.

For example we can add terminal in which user is logged in bash prompt by uncommenting following lines in /etc/bashrc file :
40               if [ "$PS1" ]; then

41                        PS1="[\u@\h:\l \W]\\$ "

42               fi


The above gives bash prompt as follows:
[root@cbitss:tty1 Desktop]#

Thus, user can change bash prompt as per the requirement.

0 comments:

Post a Comment