5169N/A# DIRECTORY MANIPULATION FUNCTIONS, REPLACES CD
0N/A# Uses global parameters _push_max _push_top _push_stack
0N/Ainteger _push_max=${CDSTACK-32} _push_top=${CDSTACK-32}
0N/A# Display directory stack -- $HOME displayed as ~
0N/A typeset dir="${PWD#$HOME/}"
0N/A select i in "$dir" "${_push_stack[@]}"
0N/A# Change directory and put directory on front of stack
0N/A -[1-9]*([0-9])) # \cd -n
0N/A n=_push_top+${1#-}-1 type=2
0N/A 1) # keep present directory
0N/A [1-9]*([0-9])) # \cd n
0N/A n=_push_top+${1}-2 type=2
0N/A *) if ((_push_top <= 0))
0N/A then type=3 n=_push_max
0N/A then if ((n >= _push_max+1))
0N/A then print -u2 cd: Directory stack not that deep.
0N/A else dir=${_push_stack[n]}
0N/A \~*) dir=$HOME${dir#\~}
0N/A dir=${OLDPWD#$HOME/}
0N/A print "\033[?${#PWD};2v$PWD\c"
3370N/A 1) # swap first two elements
0N/A _push_stack[_push_top]=$dir
0N/A 2|3) # put $dir on top and shift down by one until top
0N/A for dir in "$dir" "${_push_stack[@]}"
0N/A do ((i > n)) && break
0N/A _push_stack[_push_top=_push_top-1]=$dir
0N/A# Menu driven change directory command
0N/A typeset dir="${PWD#$HOME/}"
0N/A PS3='Select by number or enter a name: '
0N/A select dir in "$dir" "${_push_stack[@]}"