5 # Another implementation of the directory manipulation functions
6 # published in the Bolsky & Korn book : "The new Korn shell" :
7 # cd, to change current directory
8 # d, to display the stack content
9 # Eric Sanchis (eric.sanchis@iut-rodez.fr), 2012
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation, either version 3 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 shopt -s expand_aliases
31 alias integer='declare -i'
37 unalias cd 2>/dev/null
51 - ) # cd - => equivalent to : cd -1
55 -+([[:digit:]]) ) # cd -n
59 *) # cd ~ or cd dir_name
73 echo Impossible to change directory >&2
78 while (( j <= INDTOP ))
94 rep=$( \cd "$1" &>/dev/null && pwd)
97 echo cd : "$1" unknown >&2
104 if [[ "${tab[i]}" == "$rep" ]]
111 then # cd -0 => we do nothing !
114 then # the directory isn't in the stack
115 if (( INDTOP == INDMAX ))
116 then # the stack is FULL
117 # the oldest directory is removed
121 while (( m <= INDMAX ))
126 else # the new directory is added to the top of the stack
133 else # the directory is already in the stack
140 function d # display the directory stack
146 while (( $i <= $INDTOP ))
148 rep="${tab[INDTOP-i]#$HOME/}"