prompt changing on the fly

herve at titn.UUCP herve at titn.UUCP
Sat Jan 24 09:57:43 AEST 1987



Regarding the prompt setting under csh, here is the way I handle that in 
my login scripts, for what it's worth (all this on a VAX 750, 4.2):

The .login file has the following entries:

	alias	cd	'set old=$cwd; chdir \!*; set prompt = "$Ndirs$cwd> "'
	alias	back	'set back=$old; set old=$cwd; cd $back; unset back'
	alias	ndir	"dirs|wc|sed -e 's/^ *1 *//' -e 's/ .*//'"
	alias	push	'pushd \!*; set Ndirs="`ndir` - "; cd .'
	alias	pop	'popd \!*; set Ndirs="`ndir` - "; cd .'
	set	Ndirs =	"`ndir` - "
	cd .

The prompt is then the current directory preceded by the number of directories
currently on the stack (as I never remember what I'm doing with pushd and popd,
that's an information I find quite useful...).  The back command allows me to 
switch between the last two directories I used.

I did not put a "set prompt = xxxx" in my .cshrc script. In this case, the
standard '%' prompt reminds me, when I see it, that I am in a subshell.

For people who heavilly use pushd and popd and who cannot afford the delay
in the execution of ndir, just use:

	alias	cd	'set old=$cwd; chdir \!*; set prompt = "$cwd> "'
	alias	back	'set back=$old; set old=$cwd; cd $back; unset back'
	alias	push	'pushd \!*; cd .'
	alias	pop	'popd \!*; cd .'
	cd .

instead of the above, and push and pop will be faster.

FROM:	Herve Siegrist, TITN Inc.  24301 Southland Dr. Suite 200
	Hayward, CA 94545	Tel: (415) 785-5970
UUCP:	(decvax|ucbvax|ihnp4)!decwrl!sun!dlb!plx!titn!herve



More information about the Comp.unix.wizards mailing list