[comp.unix.questions] Getting csh prompt to display the current dir.

SSUCS004@vmd.cso.uiuc.edu (Jeff Gustafson) (04/03/89)

In the INFO-UNIX digest for Tue, 28 Mar 1989   V7#034,
lbn@ksuvax1.cis.ksu.edu (Lars Bo Nielsen) wrote:
(here come some thickly applied >'s)

>In article <2113@cveg.uucp> jms@hcx.uucp (Michael Stanley) writes:
>>
>>In article <1383@deimos.cis.ksu.edu>, lbn@ksuvax1.cis.ksu.edu
>>(Lars Bo Nielsen) writes:

>>>Simply (in CSH):
>>>
>>> 1) Full pathname:
>>>
>>> alias cd 'cd |*; set foo = pwd ; set prompt = $foo"% "'
>>>  [Three more examples]
>>
>>Ah, but csh includes the environment variable $cwd.  This makes setting
>>foo unnecessary.  It seems to me that you could remove the part that says:
>>
>>set foo = pwd
>>
>>and replace every occurrence of $foo with $cwd.
>
>You are right.  Here are the modified (quicker) versions:

And here, Mr. Nielsen gives the results of the suggestions made above.
However, I hasten to add that not every version of csh has the $cwd
environment variable.  I work on a Sperry 5000/90, and the Unisys proprietary
version of csh does not have $cwd (nor does it allow the old $< trick, push,
and pop).  Granted, I am an exception to a general rule, but we're always
out there somewhere and must help each other out.  (O, woe....)

Without the $cwd variable, the foo is a necessity.  One can get around the
$< problem (if one must) by coding:

             set instuff = `cat | head -1` (to read exactly one line of input)

instead of the old

            set instuff = $<  .

For the push and pop utilities, I refer you to "The C-Shell Field Guide"
by Gail Anderson and Paul Anderson.  It's the best work I've seen covering
csh.

What irks me so much is that the Sperry manuals explicitly state that $<
works.  Ah, well... we live and we learn.

I also cannot properly use the source command.  Does anyone out there have any
useful suggestions for a poor user of a brain-dead C-shell?  [I say that for
the sake of my ego; no doubt I am overlooking something, I'm a "sh" refugee.]
Your input shall be most welcome.

           Jeff Gustafson
           J-168, Academic Computing Services
           Sangamon State University
           Springfield, IL 62794-9243
           <SSUCS004@UIUCVMD>
           <SSUCS004@vmd.cso.uiuc.edu>

rikki@macom1.UUCP (R. L. Welsh) (04/05/89)

> I also cannot properly use the source command.  Does anyone out there have any
> useful suggestions for a poor user of a brain-dead C-shell?  [I say that for
...

Did you mean that "source" doesn't work right in your brain-dead C-shell or
that you weren't certain of it's use?

If it's the latter:
	source is equivalent to the "." command in sh, which means
to run a shell script in the context of the current one instead of creating
a new one.  E.g.,
	Create a short file which contains something like:

		#!/bin/csh
		setenv var new

and name it "x" and make it executable.  Then type:

	setenv var old
	x
	echo $var

"var" will still be set to "old".  But if you type:

	source x
	echo $var

"var" will now be set to "new".


In the case of the former:
	Sorry.

-- 
	- Rikki	(UUCP: grebyn!macom1!rikki)

tom@dr.uucp (Tom Rojahn) (04/06/89)

	Here is one simple way to let csh prompt your current
	directory:

	Enter following commands in /etc/cshrc or $HOME/.cshrc:

	set prompt="`pwd`% "
	alias cd 'chdir \!*; set prompt="`pwd`% "'


	Tom Rojahn
 +--------------------------------------------------------------+
 ! DataRojahn-> Tel: +479945178 Mobil: 03006606 Fax: +479945592 !
 ! uucp: dr!tom Tel: +479945180 login: public Password: Public  !
 ! USENET/EUnet:  ...!mcvax!ndosl!dr!tom   or: tom@dr.uucp      !
 +--------------------------------------------------------------+