Skip to content

Instantly share code, notes, and snippets.

@kergoth
Created February 27, 2013 02:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kergoth/5044367 to your computer and use it in GitHub Desktop.
Save kergoth/5044367 to your computer and use it in GitHub Desktop.
Portable mini-implementation of pushd/popd from the ksh docs
# These directory stack functions are based upon the versions in the Korn
# Shell documentation - http://docstore.mik.ua/orelly/unix3/korn/ch04_07.htm.
dirs() {
echo "$_DIRSTACK"
}
pushd() {
dirname=$1
cd ${dirname:?"missing directory name."} || return 1
_DIRSTACK="$PWD $_DIRSTACK"
echo "$_DIRSTACK"
}
popd() {
_DIRSTACK=${_DIRSTACK#* }
top=${_DIRSTACK%% *}
cd $top || return 1
echo "$PWD"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment