* A (new and improved) Xmas toy
@ 1993-12-22 22:49 Tom Culliton x2278
0 siblings, 0 replies; only message in thread
From: Tom Culliton x2278 @ 1993-12-22 22:49 UTC (permalink / raw)
To: rc
# 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
}
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1993-12-22 23:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-12-22 22:49 A (new and improved) Xmas toy Tom Culliton x2278
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).