From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay1.UU.NET ([192.48.96.5]) by hawkwind.utcs.toronto.edu with SMTP id <24035>; Wed, 22 Dec 1993 17:17:47 -0500 Received: from spool.uu.net (via LOCALHOST) by relay1.UU.NET with SMTP (5.61/UUNET-internet-primary) id AA09247; Wed, 22 Dec 93 17:17:10 -0500 Received: from srg.UUCP by uucp2.uu.net with UUCP/RMAIL (queueing-rmail) id 171522.29952; Wed, 22 Dec 1993 17:15:22 EST Received: from ceres.srg.af.mil by srg.srg.af.mil id aa12460; Wed, 22 Dec 93 17:02:57 EST From: culliton@srg.srg.af.mil (Tom Culliton x2278) X-Mailer: SCO System V Mail (version 3.2) To: rc@hawkwind.utcs.toronto.edu Subject: A Xmas toy Date: Wed, 22 Dec 1993 17:03:01 -0500 Message-Id: <9312221703.aa18393@ceres.srg.af.mil> # This is my Xmas present to the mailing list. It's a version of cd that # keeps track of all the directories that you've visited and lets you easily # return to any of them. I wrote it because I often find myself bouncing # back and forth between 3 or 4 different places, cd - just didn't cut it, # and pushd/popd/swapd were inconvenient. Hopefully you'll find this # useful or at least entertaining. # # Tom # The variable dirs holds the MRU directory queue fn dirs { echo $dirs } fn cd { if (! ~ $#* [01]) { echo too many arguments return 1 } switch ($1) { case - # shorthand for -1 cd $dirs(1) # recursion case -[1-9] -[1-9][0-9] # 1 -> 99 are valid cd $dirs(`{echo $1 | cut -c2-}) # recursion case -[0-9]* # catch dumb stuff echo bad numeric argument return 1 case * # also handles no args case d = $1 { # save arg (if any) '*' = $dirs # shift only works on * dirs = `{/bin/pwd} # MRU moves to front while (! ~ $* ()) # and eliminate duplicates { if (! ~ $dirs $1) dirs = ($dirs $1) shift } builtin cd $d # actually go there # and possibly fix your prompt, etc. } } }