Getting UNIX prompt to display curr

David C Lawrence tale at its.rpi.edu
Sat Mar 25 16:50:20 AEST 1989


In article <2113 at cveg.uucp> jms at hcx.uucp (Michael Stanley) writes:
MS> Ah, but csh includes the environment variable $cwd.  This makes setting
MS> foo unnecessary.  It seems to me that you could remove the part that says:

MS> 	set foo=`pwd`

MS> and replace every occurrence of $foo with $cwd.

MS> I haven't actually tested these examples so I hope I didn't just stick
MS> my foot in my mouth, but I did do something like this once so I'm pretty
MS> sure it'll work.

Well, you didn't necessarily stick your foot in your mouth.  $cwd
works just fine for people who don't care where they REALLY are in
the directory tree (ie, those who never bother with .. ).  However,
for those of us who do use .. as a convenient shorthand way to move
around directories, $cwd doesn't cut it.  If the directory to which
you changed was in reality a symbolic link, $cwd (and dirs) reports
the name of the link, not the final destination.  Using pwd for the
prompt insures that the actual current directory will be displayed.

For anyone who is really interested in the 80 000 ways that other
people are setting their prompt, here's my obligatory contribution.
Perhaps the original fellow who asked the question (with the Bourne
shell) would like to get tcsh -- prompt-people can play to their
hearts delight in it.  The following are in tcsh:

alias precmd pwd
set prompt="%m:`whoami` (%h) "

to give me:

/home/h/tale/News
consult1:tale (87) 

tcsh also has an available variable "cwdcmd" to be executed whenever
the current value of cwd changes.  This can be set to change the
window label of a shelltool, for example, by aliasing it to 

alias cwdcmd echo ^[]l$cwd^[\\

For those interested, tcsh is available from tut.cis.ohio-state.edu
via anonymous ftp.

Dave
--
      tale at rpitsmts.bitnet, tale%mts at itsgw.rpi.edu, tale at pawl.rpi.edu



More information about the Comp.unix.questions mailing list