From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from relay2.UU.NET ([192.48.96.7]) by hawkwind.utcs.toronto.edu with SMTP id <24034>; Wed, 22 Dec 1993 18:20:03 -0500 Received: from spool.uu.net (via LOCALHOST) by relay2.UU.NET with SMTP (5.61/UUNET-internet-primary) id AA17520; Wed, 22 Dec 93 18:20:09 -0500 Received: from srg.UUCP by uucp6.uu.net with UUCP/RMAIL (queueing-rmail) id 181824.11867; Wed, 22 Dec 1993 18:18:24 EST Received: from ceres.srg.af.mil by srg.srg.af.mil id aa13196; Wed, 22 Dec 93 17:49:00 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 (new and improved) Xmas toy Date: Wed, 22 Dec 1993 17:49:06 -0500 Message-Id: <9312221749.aa18791@ceres.srg.af.mil> # Amazing what an extra half hour of thought will do to improve a piece # of code. I was fretting about the size of the function, because SCO # Unix has limited environment space and managed to shave its size a bit # and make it a little cleaner. fn dirs { echo $D } fn cd { if (! ~ $#* [01]) { echo too many arguments return 1 } switch ($1) { case - # shorthand for -1 cd $D(1) # recursion case -[1-9] -[1-9][0-9] # 1 -> 99 are valid cd $D(`{echo $1 | cut -c2-}) # recursion case -[0-9]* # catch dumb stuff echo bad numeric argument return 1 case * # also handles no args case d=$D i=() { D = `{/bin/pwd} # MRU moves to front for (i in $d) # and eliminate duplicates if (! ~ $D $i) D = ($D $i) builtin cd $1 # actually go there # and fix the prompt } } }