Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!cmcl2!rutgers!lll-lcc!ames!ucbcad!ucbvax!hplabs!sdcrdcf!ism780c!mikep
From: mikep@ism780c.UUCP (Michael A. Petonic)
Newsgroups: comp.unix.wizards,comp.unix.questions
Subject: Re: The whole prompt string thing (was: PS1 and the bourne shell...)
Message-ID: <8113@ism780c.UUCP>
Date: Wed, 2-Dec-87 20:18:20 EST
Article-I.D.: ism780c.8113
Posted: Wed Dec  2 20:18:20 1987
Date-Received: Thu, 10-Dec-87 22:53:20 EST
References: <279@caus-dp.UUCP> <1311@puff.wisc.edu> <137@anumb.UUCP> <207@jc3b21.UUCP> <305@caus-dp.UUCP>
Reply-To: mikep@ism780c.UUCP (Michael A. Petonic)
Organization: Interactive Systems Corp., Santa Monica CA
Lines: 48
Xref: mnetor comp.unix.wizards:5863 comp.unix.questions:5222


Ok, how about a detailed step by step procedure (but not too
specific as I don't have the source in front of me).  it seems
obvious that the bourne shell needs to be modified.  Now, if you want
the prompt to ALWAYS show the current working directory at the beginning,
it's a simple matter.  Just modify the shell to print it out when it
prints a prompt.  Probably only one or fifteen lines of code.

Now, if you want to have a special sequence in $PS1 to indicate
that you want the cwd there, it's a different matter...

Say you want %P to represent the path in $PS1.  Here's how I would
go about it...

1) First, make another char star that will point to an internal version
of PS1.  This is to contain PS1 as it is printed out (as a prompt).

2) Parse the value for PS1 into the internal PS1 pointer (include
the cwd iff PS1 has %P in it).

3) Modify the variable setting section of the shell to change the internal
PS1 if PS1 is modified.  This includes a call to getcwd(3) (which
is VERY expensive) if the external PS1 contains %P in it.

4) Modify the section of code of the "cd" command to reset the internal PS1
(if the external PS1 contains %P) based on what the argument is to the
cd command (and to the cwd(2) call).  Instead of having it parse
through all the possible "..", etc., you could make things easier by
doing another call to getcwd(3), but again, that's expensive.

5) Modify the part of the shell that prints the prompt to instead print
out the internal version of PS1.

* Note:  This was thought up in only about 3 minutes, so it isn't the best
way.  Another way is to just store the current working directory in
an internal variable instead of an internal PS1.  In anycase, this
is just ONE of the many ways that this problem can be solved.

What the hell's so hard about it?  I know a guy who's in the
ARMY who did this to the bourne shell (it always printed the
prompt, not the flexible method I described), so if he did it,
I'm sure it's not that tough.

Thre are two alternate solutions:  Use the Korn Shell (preferred!) or
use Tim Smith's (also of ISC) solution:  $ PS1="." which
ALWAYS prints out the current working directory.

-MikeP