rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* A Xmas toy
@ 1993-12-22 22:03 Tom Culliton x2278
  0 siblings, 0 replies; only message in thread
From: Tom Culliton x2278 @ 1993-12-22 22:03 UTC (permalink / raw)
  To: rc

# 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.
		}
	}
}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1993-12-22 22:17 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:03 A 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).