[net.unix] pushd/popd in bastard csh'es

allbery@ncoast.UUCP (Brandon Allbery) (12/10/85)

Expires:

Quoted from <150@ms.UUCP> ["Re: Prompt showing current directory (just like DOS)"], by mts@ms.UUCP (Martin Stanley)...
+---------------
| While we are at it, I also have a simulation of pushd and popd (from the
| BSD4.2 csh). They are implemented via aliases and shell files. They too,
| are considerably slower than the builtin versions, but work fast
| enough.  Send me mail if you want a copy.
+---------------

Shell files?!  For pushd/popd/dirs???  Let me show you the aliases I use
(Plexus P/60, sys3/3.3; if your supplier didn't fix the &&/|| bug, replace
the && with ||):

	set cwd=(`pwd`)
	alias dirs echo $cwd
	alias popd 'chdir $cwd[2] && set cwd=($cwd[2-]); echo $cwd'
	alias pushd 'chdir \!* && set cwd=(`pwd` $cwd); echo $cwd'
	alias cd 'chdir \!* && set cwd=(`pwd` $cwd[2-])'

(I changed my ^ to ! above for you guys.  I use ! a lot; I set histchars
to ^@ even though it breaks :gs.)

It has the advantage of being compatible with 4.1 csh (as seen on a Pixel);
the directory stack is maintained in $cwd with the first element being the
current directory.  The only incompatibility is the inability to swap the
top two stack entries if pushd is given wthout an argument; if anyone
figures out how to do it with an alias, let me know, until then I'll put
up with its current behavior (I have an aliss swapd for the trivial pushd
case).  Who needs a command file?

I have an alias which *does* use a command file; it maintains my csh
environment.  If I test a new alias and it works, I type ``dumpenv''.
The alias proceeds to pipe my aliases, variables, and environment through
a command which reconstitutes the original statements, and writes files
.cshalias, .cshvar, and .cshenv; .cshrc sources .cshalias and .cshvar,
and .login sources .cshenv and .cshinit (where my startup commands reside).
It's a tad slower than the usual system, but I can dynamically modify my
environment and quickly save it.  Who says csh users suffer?

--Brandon
-- 

			Lord Charteris (thurb)

ncoast!allbery@Case.CSNet (ncoast!allbery%Case.CSNet@CSNet-Relay.ARPA)
..decvax!cwruecmp!ncoast!allbery (..ncoast!tdi2!root for business)
6615 Center St., Mentor, OH 44060 (I moved) --Phone: +01 216 974 9210
CIS 74106,1032 -- MCI MAIL BALLBERY (WARNING: I am only a part-time denizen...)