summaryrefslogtreecommitdiff
path: root/dirstack.sh
blob: 37c3bf3fba8b6d8c53e1b86dca165e39f781c4c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pushd() {
	_topush=$(pwd)
	cd "${1+"$@"}" && _DIRSTACK="$(printf '%s\n' ${_topush} ${_DIRSTACK})"
	unset _topush
}

popd() {
	if [ -z "${_DIRSTACK}" ]; then
		printf 'popd: directory stack is empty\n'
		return 1
	fi

	cd $(dirs | head -n1)
	pwd
	_DIRSTACK="$(dirs | tail +2)"
}

dirs() {
	printf '%s\n' ${_DIRSTACK}
}