-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghclone
executable file
·89 lines (72 loc) · 1.26 KB
/
ghclone
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
#!/bin/sh
set -e
usage() {
echo "Usage:"
echo " ghclone [options] <repository> [<folder>]"
echo ""
echo "Options:"
echo " -b, --branch <branch> Use <branch> instead of default branch"
echo " -d, --develop Use develop branch instead of default branch"
echo " -h, --help Display this help message"
exit 0
}
parse_args() {
USAGE=0
while [ $# -gt 0 ]; do
case "$1" in
--help | -h)
USAGE=1
;;
--branch=*)
BRANCH="${1#*=}"
;;
-b | --branch)
shift
BRANCH="$1"
;;
-d | --develop)
BRANCH="develop"
;;
*)
if [ -z "${REPO}" ]; then
case $1 in
*[/]*)
USER="${1%/*}" # wstein/setup => wstein
REPO="${1##*/}" # wstein/setup => setup
;;
*)
USER="wstein"
REPO=$1
;;
esac
elif [ -z "${FOLDER}" ]; then
FOLDER="$1"
else
echo "to many arguments: $1"
USAGE=1
fi
;;
esac
shift
done
if [ "${USAGE}" -eq 1 ]; then
usage
exit
fi
if [ -z "${REPO}" ]; then
echo "Missing arguments!"
usage
exit
fi
}
execute() {
test -n "${BRANCH}" && OPTS="--branch=${BRANCH}"
CMDLINE="git clone ${OPTS} https://github.com/${USER}/${REPO} ${FOLDER}"
echo "${CMDLINE}" >&2
${CMDLINE}
}
main() {
parse_args "$@"
execute
}
main "$@"