-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone.bash
executable file
·93 lines (67 loc) · 1.97 KB
/
clone.bash
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /bin/bash
function back () {
if [[ $1 == "b/" ]];then
exit 88
fi
return
}
function check_name () {
read -p "directory name of the cloned repository : " name ; back ${name}
while [[ ${name} == '' ]]
do
echo "error , name invalid !"
back ${name}
read -p "directory name of the cloned repository : " name ; back ${name}
done
return
}
function check_url () {
read -p "clone repository url : " url ; back ${url}
while [[ ${url} == '' ]]
do
echo "error , can't be empty !"
read -p "clone repository url : " url ; back ${url}
done
return
}
function clone () {
check_url
PS3="make directory ?"
select r in yes no
do
if [[ $r == "yes" ]];then
check_name
read -p "clone under which directory (enter directory path): " fdir ; back ${fdir}
cd $fdir 2>/dev/null
while [[ $fdir == '' || $? -eq 1 ]]
do
echo "wrong path"
read -p "clone under which directory (enter directory path): " fdir ; back ${fdir}
cd $fdir 2>/dev/null
done
mkdir ${name}
echo "start cloning......"
set -e
git clone $url "$fdir/$name/"
break
elif [[ $r == "no" ]];then
read -p "clone repository to which directory (enter directory path) : " fdir ; back ${fdir}
cd $fdir
while [[ $fdir == '' || $? -eq 1 ]]
do
echo "wrong path"
read -p "clone repository to which directory (enter directory path) : " fdir ; back ${fdir}
cd $fdir
done
echo "start cloning......"
set -e
git clone "$url" "$fdir"
break
elif [[ $REPLY == "b/" ]];then
exit 88
else echo "invalid choice !"
fi
done
return
}
clone