2 # DIRECTORY MANIPULATION FUNCTIONS PUSHD, POPD AND DIRS
4 # Uses global parameters _push_max _push_top _push_stack
5 integer _push_max=100 _push_top=100
6 # Display directory stack -- $HOME displayed as ~
9 typeset dir="${PWD#$HOME/}"
17 print -r - "$dir ${_push_stack[@]}"
20 # Change directory and put directory on front of stack
27 if ((_push_top >= _push_max))
28 then print pushd: No other directory.
31 type=1 dir=${_push_stack[_push_top]}
33 +[1-9]|+[1-9][0-9]) # pushd +n
34 integer i=_push_top$1-1
36 then print pushd: Directory stack not that deep.
39 type=2 dir=${_push_stack[i]}
41 *) if ((_push_top <= 0))
42 then print pushd: Directory stack overflow.
47 \~*) dir=$HOME${dir#\~}
49 cd "${dir:-$1}" > /dev/null || return 1
60 _push_stack[_push_top=_push_top-1]=$dir
63 _push_stack[_push_top]=$dir
66 type=${1#+} i=_push_top-1
67 set -- "${_push_stack[@]}" "$dir" "${_push_stack[@]}"
70 do (((i=i+1) < _push_max)) || break
77 # Pops the top directory
81 if ((_push_top >= _push_max))
82 then print popd: Nothing to pop.
87 dir=${_push_stack[_push_top]}
89 \~*) dir=$HOME${dir#\~}
95 integer i=_push_top$1-1
97 then print pushd: Directory stack not that deep.
100 while ((i > _push_top))
101 do _push_stack[i]=${_push_stack[i-1]}
105 *) print pushd: Bad directory.
108 unset '_push_stack[_push_top]'
109 _push_top=_push_top+1