Date: Mon, 03 Aug 1998 17:37:45 -0700 From: Studded <Studded@dal.net> To: Sascha Schumann <sas@schell.de> Cc: William Woods <wwoods@cybcon.com>, "freebsd-questions@FreeBSD.ORG" <freebsd-questions@FreeBSD.ORG> Subject: Re: BASH prompt question Message-ID: <35C657D9.4B2577D4@dal.net> References: <Pine.LNX.3.96.980803142023.11763B-100000@www.schell.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Sascha Schumann wrote: > > On Sun, 2 Aug 1998, William Woods wrote: > > > I would like to make my bash prompt show a little more info, like what dir the > > user is in. How would I do this? > > Edit /etc/profile and insert at the end: > > test "$SHELL" = "/bin/bash" && test -e ~/.bashrc && source ~/.bashrc Why are you inserting a test to accomplish something that bash does by default? > PS1='\u@\h:`pwd -P` $ ' > export PS1 Again, working too hard. :) Why call a shell function every time you hit return? The following accomplishes what you have there, and adds your correction for the \$: export PS1='\u@\h: \w \$' This syntax is available in bash 2 and above, but you should be using bash 2 anyway. :) If you're using xterm I use the following prompt to add information to my title bar, put user@ME (which is my machine, since I log into a lot of different ones) and the current working directory on one line, and the actual prompt below that since I like the full path in the prompt but it can get too long. if [ $TERM = xterm ]; then export PS1='\[\e]1;My Desk\a\e]2;$PWD\a\][\u@ME \w]\n \#\$ ' else export PS1='[\u@ME \w]\n \#\$ ' fi You can parse the line that works for xterm's as follows: \[ - start a sequence of non-printing characters \e]1;My Desk\a \e - an ASCII escape character (033) ]1; - xterm'ism for the name of the icon (works for wm's like afterstep) My Desk - literal text string \a - an ASCII bell character (07) This ends the first xterm sequence \e]2;$PWD\a In the second xterm sequence I like to use $PWD rather than \w because otherwise it puts '~' in the title when you use just 'cd' to return to your home. \] - ends the non-printing character part of the prompt. [\u@ME \w] [ - literal [ character \u - the username of the current user @ME - literal characters \w - the current working directory ] - literal ] character \n - newline \# - the command number of this command \$ - if the effective UID is 0, a #, otherwise a $ Example while I'm in my home directory: [myusername@ME ~] 22$ Another example: [myusername@ME /usr/ports/shells/bash2] 23$ Here's some info from misc.c in xterm's source about the escape codes for the title and icon: case 0: /* new icon name and title*/ case 1: /* new icon name only */ case 2: /* new title only */ This may be more details than the original poster wanted, but the goal is to show what's possible. Some people have implemented colored prompts using ansi escape codes, but I haven't gotten that obsessed yet. :) Hope this helps, Doug -- *** Chief Operations Officer, DALnet IRC network *** When you don't know where you're going, every road will take you there. - Yiddish Proverb To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?35C657D9.4B2577D4>