-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshgg
41 lines (34 loc) · 858 Bytes
/
zshgg
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
37
38
39
40
i=1
HERE=`pwd`
VALID_HERE=${HERE//\//\\\/}
[[ ! -f ~/.gg/zshdir ]] && touch ~/.gg/zshdir
ALREADY_EXIST=`grep ^${HERE}$ ~/.gg/zshdir`
declare -a godirs
while true; do
[[ $1 = "a" ]] && [[ x${ALREADY_EXIST} = "x" ]] && echo "${HERE}" >> ~/.gg/zshdir
[[ $1 = "a" ]] && break
[[ $1 = "d" ]] && [[ x${ALREADY_EXIST} != "x" ]] && sed -i "/^${VALID_HERE}$/d" ~/.gg/zshdir
[[ $1 = "d" ]] && break
while true ; do
read line
if [ $? -ne 0 ] ; then
break
fi
[[ -d $line ]] || continue
echo -e "\033[$(( 31 + $i % 3 ));40m" $i: $line
godirs[$i]=$line
let i=$i+1
done < ~/.gg/zshdir
echo -e "\033[0m"
if [[ $1 =~ ^[1-9]{1}$ ]]; then
n=$1
else
echo -n 'where to go? '
read -k 1 -t30 n
echo
fi
if [[ $n =~ ^[1-9]{1}$ ]]; then
[[ "x"${godirs[${n}]} != "x" ]] && cd ${godirs[${n}]}
fi
break
done