Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: Customize bash shell prompt
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Duplicate Threads
View previous topic :: View next topic  
Author Message
e980238
Tux's lil' helper
Tux's lil' helper


Joined: 13 Apr 2004
Posts: 89

PostPosted: Mon Jun 07, 2004 5:04 pm    Post subject: HOWTO: Customize bash shell prompt Reply with quote

Hey all,

I figured I would share how I customized the shell prompt for all of my terminals.

First make a file called /etc/prmpt This will define the colors based on the bash color codes which can be found in the link below, and also the special characters to add things to your prompt, like the time, current working dir, etc. have it contain this:

Code:


BBLUE="\[\033[34;40m\]"
GRN="\[\033[37m\]"
CYAN="\[\033[36m\]"
PURP="\[\033[35m\]"
N="\[\033[0m\]"
B="\[\033[1m\]"
export PS1="$B$BBLUE[$N$GRN\\u$B$BBLUE]$N$B:$N$CYAN\\w$N\\$ $N"


Second, make a file (if it doesnt already exist) called /etc/bashrc and have it contain this:

Code:

source /etc/prmpt


Third, make sure your ~/.bashrc contains this. It will make it so that whenever you open a terminal or log into a text console, your prompt settings will get exported and will effectively be "turned on":

Code:


if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi


this page http://www-106.ibm.com/developerworks/library/l-tip-prompt/ has some info on the escape characters and the colors which you can use and their coresponding color code.

Have fun!
_________________
Theres no place like ::1
Back to top
View user's profile Send private message
jftuga
Tux's lil' helper
Tux's lil' helper


Joined: 21 Jan 2004
Posts: 139
Location: Athens, GA

PostPosted: Mon Jun 07, 2004 6:34 pm    Post subject: Reply with quote

First off, nice howto. I think a lot of people will be changing their prompts after reading your article. :)

Might it be advisable to wrap variable names in curly braces?

For example:

${BLUE} instead of $BLUE

-John
Back to top
View user's profile Send private message
BlindSpy
Apprentice
Apprentice


Joined: 20 Mar 2004
Posts: 263

PostPosted: Mon Jun 07, 2004 11:34 pm    Post subject: Reply with quote

Code:
export PS1='\e[01;32m\]\H\e[01;34m\][\@]\$ \e[00m\]'


someone wanna help me with the brackets on this one? I'm getting wrapping errors.
Back to top
View user's profile Send private message
pagerc@ufl.edu
n00b
n00b


Joined: 02 Jan 2004
Posts: 15

PostPosted: Tue Jun 08, 2004 6:02 am    Post subject: Reply with quote

There's a better prompt thing, not a howto, but a bunch of informative prompts https://forums.gentoo.org/viewtopic.php?t=5850&highlight=bash+prompt

I also have a spiffy prompt you can look at here:
http://fidget.cns.ufl.edu/~pagerc/prompt

and a corresponding screen shot:
http://fidget.cns.ufl.edu/~pagerc/sweet.png
Back to top
View user's profile Send private message
e980238
Tux's lil' helper
Tux's lil' helper


Joined: 13 Apr 2004
Posts: 89

PostPosted: Tue Jun 08, 2004 11:56 am    Post subject: Reply with quote

pagerc@ufl.edu wrote:
There's a better prompt thing, not a howto, but a bunch of informative prompts https://forums.gentoo.org/viewtopic.php?t=5850&highlight=bash+prompt


Longer, yes. Better, no?

The "tip" in that post does not really, as you said, say howto do it. That is why I decided to start this post, so people would understand what to do with all of the variable exporting.
_________________
Theres no place like ::1
Back to top
View user's profile Send private message
BlindSpy
Apprentice
Apprentice


Joined: 20 Mar 2004
Posts: 263

PostPosted: Wed Jun 09, 2004 7:02 pm    Post subject: Reply with quote

BlindSpy wrote:
Code:
export PS1='\e[01;32m\]\H\e[01;34m\][\@]\$ \e[00m\]'


someone wanna help me with the brackets on this one? I'm getting wrapping errors.


:) please?
Back to top
View user's profile Send private message
mholtz
Tux's lil' helper
Tux's lil' helper


Joined: 04 Feb 2004
Posts: 110
Location: Ohio, USA

PostPosted: Tue Jun 22, 2004 3:08 am    Post subject: Reply with quote

Could someone explain to me how to make my root prompt use the same prompt as my normal user account when using the command su? It seems that by default su does not execute /root/.bashrc
Back to top
View user's profile Send private message
yuppienetworking
Tux's lil' helper
Tux's lil' helper


Joined: 23 Feb 2004
Posts: 110
Location: Caracas - Venezuela

PostPosted: Tue Jun 22, 2004 4:13 am    Post subject: Reply with quote

Code:

man su
...
su is used to become another user during a login session. Invoked with-
       out a username, su defaults to becoming the super  user.  The  optional
       argument  -  may be used to provide an environment similiar to what the
       user would expect had the user logged in directly.
....


I other words, when you su, you are not executing config files like .bashrc or .bash_profile. If you want to execute these files when su-ing try su -
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Duplicate Threads All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum