Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Extra informative Bash prompt
View unanswered posts
View posts from last 24 hours

Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9  Next  
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
Techie2000
Guru
Guru


Joined: 16 May 2002
Posts: 344

PostPosted: Sat Jun 01, 2002 12:23 am    Post subject: Changing the default .bash_config Reply with quote

where is the default .bash_config so I can go and make it say:
root@linux:/>
instead of
linux /#
Back to top
View user's profile Send private message
tyreth
Apprentice
Apprentice


Joined: 27 May 2002
Posts: 238
Location: Melbourne, Australia

PostPosted: Sat Jun 01, 2002 4:52 am    Post subject: Reply with quote

That's just the PS1 environment variable. Throw it in /etc/profile or /etc/bashrc I think. If you want it just for one user then I think it's ~/.bashrc

Hope that helps. I think there's a bash howto on www.linuxdocs.org
Back to top
View user's profile Send private message
grakker
Tux's lil' helper
Tux's lil' helper


Joined: 17 Apr 2002
Posts: 100

PostPosted: Sat Jun 01, 2002 2:04 pm    Post subject: Bash Prompt Tutorial Reply with quote

If you want a pretty sick tutorial on setting the bash prompt, the man himself, drobbins, wrote a cool one that on the ibm site here
http://www-106.ibm.com/developerworks/linux/library/l-tip-prompt.
Back to top
View user's profile Send private message
wont-i
n00b
n00b


Joined: 06 Jun 2002
Posts: 8

PostPosted: Sun Jun 23, 2002 5:16 am    Post subject: Extra informative Bash prompt Reply with quote

I've got a bash prompt that I've been using for quite awhile now, and that others that I've shown it to often want to make use of, so I thought I'd offer it up here, too.

It's a 3 line prompt, but I find it provides me almost every bit of info about my current environment I need or want at a glance.

Note: The following assumes a black terminal background. If you're using a white background, you'll need to adjust the color codes to be more visible (as can be seen in the example prompt shown below).

Code:
PS1="\n\[\033[35m\]\$(/bin/date)\n\[\033[32m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\$(/usr/bin/tty | /bin/sed -e 's:/dev/::'): \[\033[1;36m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] -> \[\033[0m\]"




This ends up producing a prompt such as the following:
Code:

Sun Jun 23 00:33:58 EDT 2002
/usr/src/linux
wont@calvin: pts/3: 23 files 3.8Mb ->


where:
Line 1-- current date and time
Line 2-- current working directory
Line 3-- username @ host: console number: # of files in directory total size of directory on disk ->

Hope this is of interest to someone out there. :-)

Will
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20053

PostPosted: Sun Jun 23, 2002 6:12 am    Post subject: Reply with quote

I've not botherd to relearn prompt code. I don't need all that info, but this certainly makes
it easier to learn :D

Thanks for the tip.


EDIT:
Some other bash prompt threads:
_________________
Quis separabit? Quo animo?


Last edited by pjp on Sat Dec 25, 2004 3:33 am; edited 1 time in total
Back to top
View user's profile Send private message
andee
n00b
n00b


Joined: 04 Jun 2002
Posts: 41

PostPosted: Sun Jun 23, 2002 6:50 am    Post subject: Re: Extra informative Bash prompt Reply with quote

thanks ;)
My prompt looks really pretty right now
Back to top
View user's profile Send private message
JefP@@
Apprentice
Apprentice


Joined: 09 May 2002
Posts: 179
Location: Belgium

PostPosted: Sun Jun 23, 2002 9:58 am    Post subject: Reply with quote

it sure is interesting ... I'll try it out once, when I've got the time ;)
Back to top
View user's profile Send private message
bert
n00b
n00b


Joined: 20 Jun 2002
Posts: 11
Location: Amsterdam

PostPosted: Sun Jun 23, 2002 11:08 am    Post subject: Reply with quote

Here's a bash prompt that shows battery status on a laptop. Needs apm tools / kernel support available (and awk).

Code:
PS1="\`apm|awk '\$5~/%/{print \$5}\$6~/%/{print \$6}'\` [\\u@\\h:\\w] \\$ "


.. and this is what it looks like

Quote:
100% [bert@brahms:~/movies] $
99% [bert@brahms:~/movies] $
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20053

PostPosted: Sun Jun 23, 2002 5:01 pm    Post subject: Reply with quote

Hope you don't mind, I edited your prompt to produce mine. I removed the time, # of files
and dir size. Changed the look a tiny bit, will probably change colors in the future.
Code:
PS1='\n\[\033[32m\]\w\n\[\033[0m\][\[\033[1;31m\]\u@\h \[\033[1;34m\]$(/usr/bin/tty | /bin/sed -e '\''s:/dev/::'\'')\[\033[0m\]] \[\033[0m\]'


/usr/portage
[user@hostname pty/s0]

Again, meant for a dark background. 1st line is current directory path. 2nd line is user
and hostname with terminal enclosed in [ ] (Hard to see here, they are white).
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
bone
Apprentice
Apprentice


Joined: 07 Jun 2002
Posts: 255
Location: Midwest, USA

PostPosted: Wed Jun 26, 2002 12:01 pm    Post subject: Reply with quote

About 5 years ago. I borrowed the sets from a bashcolor script and did something similar.

[This is from my /etc/profile file]

# Color Variables for Prompt
GRAD1='\333\262\261\260'
GRAD2='\260\261\262\333'
YLOBRN='\[\033[01;33;43m\]'
WHTBRN='\[\033[01;37;43m\]'
REDBRN='\[\033[00;31;43m\]'
REDBLK='\[\033[00;31;40m\]'
PPLBLK='\[\033[01;35;40m\]'
WHTBLK='\[\033[01;37;40m\]'
NONE='\[\033[00m\]'
HBLK='\[\033[00;30;30m\]'
HBLU='\[\033[01;34;34m\]'
BLU='\[\033[00;34;34m\]'
YEL='\[\033[00;33;33m\]'
WHT='\[\033[01;37;37m\]'
PRPL='\[\033[00;34;35m\]'
RED='\[\033[01;31;31m\]'
NORM='\[\033[01;00;0m\]'

export GRAD1 GRAD2 YLOBRN WHTBRN REDBRN REDBLK PPLBLK WHTBLK NONE HBLK HBLU BLU YEL WHT PRPL RED NORM

# Prompt Settings
if [ `/usr/bin/whoami` = 'root' ]
then
if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
then
PS1='\n'$WHT'*'$NONE'['$HBLU'\u'$WHT'@'$HBLU'\h'$WHT':'$HBLU'\W'$NONE']'$NONE' '
PS2='\n'$WHT'*'$NONE'['$HBLU'\u'$WHT'@'$HBLU'\h'$WHT':'$HBLU'\W (2)'$NONE']'$NONE' '
fi
else
if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
then
PS1='\n'$NONE'['$HBLU'\u'$WHT'@'$HBLU'\h'$WHT':'$HBLU'\W'$NONE']'$NONE' '
PS2='\n'$NONE'['$HBLU'\u'$WHT'@'$HBLU'\h'$WHT':'$HBLU'\(2)'$NONE']'$NONE' '
fi
fi

================

[user@host:directory]

What this does is make a very nicely colored prompt that looks well at home with both white and black backgrounds (but probably looks better with black background). And the added feature of when your root, it sets your prompt with a star in front of it like this.

*[root@host:directory]


I am in a habit of having so many sessions running, that I tend to forget which one is root or not, and just grab the session and start working. its very bad to test untested or foreign code as user root, so this helps me to make sure i do not trash a system by running bad/rogue code.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20053

PostPosted: Wed Jun 26, 2002 5:09 pm    Post subject: Reply with quote

It is also very bad to intend to reboot a remote client and forget that you are in the
server terminal. Fortunately it was during a setup phase :D
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
TGL
Bodhisattva
Bodhisattva


Joined: 02 Jun 2002
Posts: 1978
Location: Rennes, France

PostPosted: Wed Jun 26, 2002 10:26 pm    Post subject: Reply with quote

There exists a program called "bashish" which allows you to switch between a lot of prompts (from the best to the ugliest ones):
http://bashish.sourceforge.net/

There is no ebuild as far as I know, maybe I'll write one someday...

-- T.
Back to top
View user's profile Send private message
HammeR
n00b
n00b


Joined: 09 Jun 2002
Posts: 17

PostPosted: Sun Jun 30, 2002 4:59 pm    Post subject: Reply with quote

Sorry for being such a n00b, but where do I put this? In ~/.bashrc ?

EDIT: Did some research and found out that this should be in /etc/profiles .. :)
_________________
"Linux is communism" - Balmer, Microsoft.
Back to top
View user's profile Send private message
Spark
Tux's lil' helper
Tux's lil' helper


Joined: 30 Jun 2002
Posts: 87

PostPosted: Wed Jul 03, 2002 6:02 pm    Post subject: Reply with quote

Thx. :) This is my one now:
PS1='\[\033[0m\][\[\033[1;36m\]\w\[\033[0m\]] \[\033[0m\]'

Looks like this:
[/usr/src/linux]

(only good for black background of course)
and that's everything I need =) simplicity rules.
Back to top
View user's profile Send private message
Spark
Tux's lil' helper
Tux's lil' helper


Joined: 30 Jun 2002
Posts: 87

PostPosted: Thu Jul 04, 2002 7:24 pm    Post subject: Reply with quote

Hmm, I put this in /etc/profile but it only works on tty, not in xterm. Can anyone tell me what I have to do to get it working in X?
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20053

PostPosted: Thu Jul 04, 2002 10:28 pm    Post subject: Reply with quote

Try putting it in your ~/.bashrc file
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
tfoss
n00b
n00b


Joined: 04 Jul 2002
Posts: 8

PostPosted: Thu Jul 04, 2002 10:31 pm    Post subject: Try .bashrc Reply with quote

Spark wrote:
Hmm, I put this in /etc/profile but it only works on tty, not in xterm. Can anyone tell me what I have to do to get it working in X?


Try putting it in your ~/.bashrc.

(If i recall, /etc/profile is read only if its a login shell, not an interactive shell (which xterm things are)... ~/.bashrc is read for both...)

-Ted
Back to top
View user's profile Send private message
Spark
Tux's lil' helper
Tux's lil' helper


Joined: 30 Jun 2002
Posts: 87

PostPosted: Thu Jul 04, 2002 11:39 pm    Post subject: Reply with quote

Great that worked, thanks. :)
Back to top
View user's profile Send private message
Techie2000
Guru
Guru


Joined: 16 May 2002
Posts: 344

PostPosted: Fri Jul 05, 2002 5:51 pm    Post subject: Reply with quote

one of the great things about Linux :). Very customizable...
Back to top
View user's profile Send private message
ee99ee2
Guru
Guru


Joined: 18 Jun 2002
Posts: 307
Location: Murfreesboro, TN, USA

PostPosted: Sat Jul 06, 2002 3:24 am    Post subject: Reply with quote

Here's my very simple one:

Code:
PS1="[\[\033[32m\]\w\[\033[01;00;0m\]]\$ "
Back to top
View user's profile Send private message
Ard Righ
Guru
Guru


Joined: 24 Jun 2002
Posts: 337
Location: Wellington, NZ

PostPosted: Sat Jul 06, 2002 11:50 am    Post subject: Reply with quote

When you mention putting that prompt in ~/.bashrc do you mean for each user, for root only, or what ?

Is there one file location that works for all users (including root) and whether it is X or not.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20053

PostPosted: Sat Jul 06, 2002 4:29 pm    Post subject: Reply with quote

Ard Righ wrote:
When you mention putting that prompt in ~/.bashrc do you mean for each user, for root only, or what ?
~ translates to 'home directory'. So that would be for 'each user'.

Quote:
Is there one file location that works for all users (including root) and whether it is X or not.
/etc/profile works for all not including X.

You might investigate 'man bash' for more info, though I'm not aware of a single file for all.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
Ard Righ
Guru
Guru


Joined: 24 Jun 2002
Posts: 337
Location: Wellington, NZ

PostPosted: Sat Jul 06, 2002 5:15 pm    Post subject: Reply with quote

ok sweet. There aren't many user accounts on the machines I have, so not a great biggie :)
Back to top
View user's profile Send private message
wizy
Tux's lil' helper
Tux's lil' helper


Joined: 26 May 2002
Posts: 133

PostPosted: Sat Jul 06, 2002 5:49 pm    Post subject: "works for all" Reply with quote

You could also edit the .bashrc in /etc/skel so when new users are added and it uses that directory as the template, they get the new prompt.
Back to top
View user's profile Send private message
wyrickre
n00b
n00b


Joined: 10 Jul 2002
Posts: 27
Location: Colorado Springs, CO

PostPosted: Thu Jul 18, 2002 6:49 am    Post subject: Re: Try .bashrc Reply with quote

tfoss wrote:
Spark wrote:
Hmm, I put this in /etc/profile but it only works on tty, not in xterm. Can anyone tell me what I have to do to get it working in X?


Try putting it in your ~/.bashrc.

(If i recall, /etc/profile is read only if its a login shell, not an interactive shell (which xterm things are)... ~/.bashrc is read for both...)

-Ted


Most (if not all) terminals under X (xterm, gnome-terminal, Konsole, rxvt, etc) support the -ls option that specifies the terminal should run as a "login shell". IIRC, this will cause /etc/profile to get read and executed... If I'm correct, putting your prompt in /etc/profile would then affect all users who run shells that read /etc/profile.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9  Next
Page 1 of 9

 
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