current pwd in prompt

Geoffrey R. Walton geoff at ncr-sd.SanDiego.NCR.COM
Sat Feb 13 10:05:16 AEST 1988


Bill Davidsen writes:

	that someone else wrote:

Can anyone explain to me how to get my prompt to be the
current directory? I have tried several methods without
any success. It seems that no matter what method I try,
the prompt is evaluated once and never changes.

	[so he said]

>You use the value of PWD, which is the name you want. i.e.:
>	PS1='$PWD > '
>I have seen people saying that you can use `pwd` in the prompt, but
>that doesn't work in any of the versions I have seen over the last
>few years. $PWD does.

All this is well and good for the Bourne shell, but much more is
possible with csh or (I've been told, we don't have it) ksh.

I have aliases which include history number, machine name, AND
current directory as pieces of my prompt.  Sure, it's
cumbersome, but it keeps me from getting lost as I bounce from
machine to machine (is it seven or eight?) and wander all over
the file system of each.  A long prompt is MUCH better than a
trail of bread crumbs.

All seriousness aside, here are tha aliases I use -- and no,
they DON'T add a lot of overhead; "pwd" and "uuname" are _NOT_
evaluated evertime I get a prompt, only when I change directory.

   set prompt="\!:`uuname -l`:[`pwd`] "
   alias pushd	'pushd \!* ; set prompt="\\!:`uuname -l`:[`pwd`] "'
   alias popd	'popd ; set prompt="\\!:`uuname -l`:[`pwd`] "'
   alias cd	'cd \!* ; set prompt="\\!:`uuname -l`:[`pwd`] "'

Of course, you COULD use $cwd, if you wanted.

#include <all_usual_disclaimers.h>

Geoff Walton
Software Publications
NCR E&M San Diego
geoff.walton at SanDiego.NCR.COM
or
{sdcsvax,cbosgd,pyramid,nosc.ARPA,ihnp4}!ncr-sd!geoff
Even the smallest problem becomes unsolvable if enough
meetings are held to discuss it.



More information about the Comp.unix.questions mailing list