Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!sahayman From: sahayman@iuvax.cs.indiana.edu (Steve Hayman) Newsgroups: comp.unix.questions Subject: Re: Bourne Shell Question? Keywords: PS1 Message-ID: <17123@iuvax.cs.indiana.edu> Date: 2 Feb 89 05:00:15 GMT References: <8517@dasys1.UUCP> <201@carroll1.UUCP> <1895@lindy.Stanford.EDU> Reply-To: sahayman@iuvax.cs.indiana.edu (Steve Hayman) Organization: Computer Science Department, Indiana University Lines: 61 Every year someone asks "How can I put the current directory in my bourne shell prompt". Every year some people reply "Most bourne shells can't do that." How 'bout this. (tested under ultrix 3.0 only but (famous last words) I think it will work on most bourne shells.) The idea is to write a script called "chd" that puts its argument in a file and sends a signal to the parent shell; the parent traps this signal and resets PS1 according to the contents of the file, and cd's to the contents of the file. In your .profile # Put the ID of this login shell into the environment so that # "chd" can get at it SHELLPID=$$ export SHELLPID # A signal that "chd" will use to cause our login shell # to reevaluate its prompt. I don't know what the best # one to use would be but 16 (SIGURG) seemed fairly # obscure. Too bad our /bin/sh won't let you trap SIGUSR1. PROMPTSIG=16 export PROMPTSIG # What to do when we get the prompt signal. # The prompt will be set to "directory$ ". You could # easily use some other format. trap 'PS1="`cat /tmp/cd-$SHELLPID`\$ "; cd `cat /tmp/cd-$SHELLPID`' $PROMPTSIG In an executable file called "chd" somewhere in your PATH, put this, which conveniently produces an error message if the named directory doesn't exist. cd $1 && echo $1 >/tmp/cd-$SHELLPID && kill -$PROMPTSIG $SHELLPID And you just use "chd directory" and voila, current directory in your prompt (except for the first time you log in): $ chd /tmp /tmp$ chd /usr /usr$ pwd /usr /usr$ chd no-such-dir chd: no-such-dir: bad directory /usr$ pwd /usr Now, I don't use /bin/sh as my login shell, and I only tried this for about five minutes, so someone on the net may well find some reason why this won't work in general. But it might be a start. ..Steve -- Steve Hayman Workstation Manager Computer Science Department Indiana U. sahayman@iuvax.cs.indiana.edu