Thursday, December 15, 2011

pushd popd dirs for ksh

Mainly for ksh88. ksh93 users can set their FPATH to wherever the fun/ directory is, as per http://www.opensource.apple.com/source/ksh/ksh-4/ksh/src/cmd/ksh93/fun/.

unset DIRSTACK
function dirs {
  print "$PWD" "${DIRSTACK[@]}"
}
function pushd {
  : ${@?'no other directory'}
  cd "$@" && set -A DIRSTACK "$OLDPWD" "${DIRSTACK[@]}" && print "$PWD" "${DIRSTACK[@]}"
}
function popd {
  : ${DIRSTACK[@]?'directory stack empty'}
  cd "${DIRSTACK[0]}" && unset DIRSTACK[0] && set -A DIRSTACK "${DIRSTACK[@]}" && print "$PWD" "${DIRSTACK[@]}"
}

No comments: