Created
February 27, 2013 02:13
-
-
Save kergoth/5044367 to your computer and use it in GitHub Desktop.
Portable mini-implementation of pushd/popd from the ksh docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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