-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdi.sh
executable file
·36 lines (33 loc) · 1.12 KB
/
cdi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# source bash
unalias cd
if [ "$1" == ',,' ] || [ "$1" == '--' ] # Alias { ,, -- } = ..
then
cd ..
fi
if [ "$1" != '/' ] && [ "$1" != '-' ] && [ "$( echo $1 | grep ' ' )" == '' ]
then
DIR=$( echo $1 | sed -e 's/\/$//' )
if [ "$( echo $DIR | grep \/ )" == '' ]
then
ARRAY=$( /usr/bin/ls -la | grep ^[dl] | sed -e 's/ * /\t /g' | cut -f 9 | sed -e 's/ //g' | grep ^"$DIR" | head -n 1 )
if [ "$1" == '' ]
then
cd
else
if [ "$ARRAY" == '' ]
then
DIR=$( echo $DIR | tr 'A-Z' 'a-z' )
ARRAY="$( /usr/bin/ls -la | grep ^[dl] | sed -e 's/ * /\t /g' | cut -f 9 | sed -e 's/ //g' | tr 'A-Z' 'a-z' )"
POS_DIR=$( echo $ARRAY | tr ' ' '\n' | grep -E "^$DIR" )
POS_DIR=$( echo $ARRAY | tr ' ' '\n' | cat -n | grep -E "$POS_DIR" )
cd $( /usr/bin/ls -la | grep ^[dl] | sed -e 's/ * /\t /g' | cut -f 9 | sed -e 's/ //g' | tr ' ' '\n' | head -n $( echo $POS_DIR | cut -f 1 --delimiter=' ' ) | tail -n 1 )
else
cd $ARRAY
fi
fi
else
cd $DIR
fi
else
cd "$1"
fi