pushd/popd in bastard csh'es
Brandon Allbery
allbery at ncoast.UUCP
Tue Dec 10 10:59:16 AEST 1985
Expires:
Quoted from <150 at ms.UUCP> ["Re: Prompt showing current directory (just like DOS)"], by mts at 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 at Case.CSNet (ncoast!allbery%Case.CSNet at 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...)
More information about the Comp.unix.wizards
mailing list