From owner-freebsd-questions Mon Aug 3 17:38:12 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id RAA05886 for freebsd-questions-outgoing; Mon, 3 Aug 1998 17:38:12 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from dt053nd2.san.rr.com (dt053nd2.san.rr.com [204.210.34.210]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id RAA05880 for ; Mon, 3 Aug 1998 17:38:06 -0700 (PDT) (envelope-from Studded@dal.net) Received: from dal.net (Studded@localhost [127.0.0.1]) by dt053nd2.san.rr.com (8.8.8/8.8.8) with ESMTP id RAA07071; Mon, 3 Aug 1998 17:37:46 -0700 (PDT) (envelope-from Studded@dal.net) Message-ID: <35C657D9.4B2577D4@dal.net> Date: Mon, 03 Aug 1998 17:37:45 -0700 From: Studded Organization: Triborough Bridge & Tunnel Authority X-Mailer: Mozilla 4.05 [en] (X11; I; FreeBSD 2.2.6-STABLE-0507 i386) MIME-Version: 1.0 To: Sascha Schumann CC: William Woods , "freebsd-questions@FreeBSD.ORG" Subject: Re: BASH prompt question References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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