1N/A# DIRECTORY MANIPULATION FUNCTIONS PUSHD, POPD AND DIRS
1N/A# Uses global parameters _push_max _push_top _push_stack
1N/Ainteger _push_max=100 _push_top=100
1N/A# Display directory stack -- $HOME displayed as ~
1N/A typeset dir="${PWD#$HOME/}"
1N/A print -r - "$dir ${_push_stack[@]}"
1N/A# Change directory and put directory on front of stack
1N/A if ((_push_top >= _push_max))
1N/A then print pushd: No other directory.
1N/A type=1 dir=${_push_stack[_push_top]}
1N/A +[1-9]|+[1-9][0-9]) # pushd +n
1N/A integer i=_push_top$1-1
1N/A if ((i >= _push_max))
1N/A then print pushd: Directory stack not that deep.
1N/A type=2 dir=${_push_stack[i]}
1N/A *) if ((_push_top <= 0))
1N/A then print pushd: Directory stack overflow.
1N/A \~*) dir=$HOME${dir#\~}
1N/A dir=${OLDPWD#$HOME/}
1N/A _push_stack[_push_top=_push_top-1]=$dir
1N/A _push_stack[_push_top]=$dir
1N/A type=${1#+} i=_push_top-1
1N/A set -- "${_push_stack[@]}" "$dir" "${_push_stack[@]}"
1N/A do (((i=i+1) < _push_max)) || break
1N/A# Pops the top directory
1N/A if ((_push_top >= _push_max))
1N/A then print popd: Nothing to pop.
1N/A dir=${_push_stack[_push_top]}
1N/A \~*) dir=$HOME${dir#\~}
1N/A cd "$dir" || return 1
1N/A integer i=_push_top$1-1
1N/A if ((i >= _push_max))
1N/A then print pushd: Directory stack not that deep.
1N/A while ((i > _push_top))
1N/A do _push_stack[i]=${_push_stack[i-1]}
1N/A *) print pushd: Bad directory.
1N/A unset '_push_stack[_push_top]'
1N/A _push_top=_push_top+1