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