# You will find appended a small shell script that defines under a stock
# System V Bourne shell the pushd, popd, dirs commands of csh(1). They are
# trivially adapted to the Korn shell. I have taken care to make them as
# robust as possible.
# Piercarlo Grandi

# changed `pwd` to $PWD since ksh maintains $PWD
# removed $HOME references since ksh groks ~
# GGP.

DIRS=''

# We do a few contortions to ensure correct behaviour
# if directory pathnames contain spaces et similia.

pushd()
{
    CWD="$PWD"

	case "$1" in
	'')	case "$DIRS" in
		'') echo "directory stack empty"; return 1;;
		esac
		set $DIRS; eval cd "$1"; >/dev/null || return 1
		shift; DIRS="'$CWD' $@"; pwd;;

	*)	cd "$1" || return 1
		DIRS="'$CWD' $DIRS";;
	esac
	return 0
}

popd()
{
	case "$DIRS" in
	'') echo "directory stack empty"; return 1;;
	esac
	set $DIRS; eval cd "$1"
	shift; DIRS="$*"; pwd
	return 0
}

dirs()
{
    CWD="$PWD" || return 1
	eval echo "'$CWD' $DIRS"
	return 0
}

alias d+=pushd
alias d-=popd

# Piercarlo "Peter" Grandi				| ARPA: pcg%uk.ac.aber.cs@nsfnet-relay.ac.uk
# Dept of CS, UCW Aberystwyth			| UUCP: ...!mcsun!ukc!aber-cs!pcg
# Penglais, Aberystwyth SY23 3BZ, UK	| INET: pcg@cs.aber.ac.uk

# I kept PG's signoff since these were his idea and I like them - if they break
# for you it's most likely my fault, don't blame him. GGP.
